#[cfg(not(feature = "no_std"))]
use core::hash::Hash;
#[cfg(not(feature = "no_std"))]
use std::collections::HashMap;
#[cfg(not(feature = "no_std"))]
pub fn two_sum<T: Hash + Eq + Clone + core::ops::Sub<Output = T>>(
array: &[T],
target: &T,
) -> Result<(usize, usize), ()> {
let mut table: HashMap<&T, usize> = HashMap::new();
for i in 0..array.len() {
let sub = target.clone() - array[i].clone();
match table.get(&sub) {
Some(index) => {
return Ok((*index, i));
}
None => {
table.insert(&array[i], i);
}
}
}
return Err(());
}