DEV Community

Discussion on: Data Structures & Algorithms using Rust: Two Sum

Collapse
 
shahenshah profile image
ShaikShahinsha

Hello>>>Shiva .... can we achieve tagetsum using Set collection of Rust....
Here , i tried with that Set approach..... it returns me empty array.... could you please help me out on this!!!!

fn targetTwoSum(vecval: Vec, tagetSum:i32)-> Vec{
let mut sets: HashSet = HashSet::new();
for i in vecval{
let potential_match = tagetSum - i;

// println!("the potential_match : {}",potential_match);
if let Some(pos) = sets.get(&potential_match){
println!("entering in if");
return vec![i,*pos];
}

sets.insert(potential_match);

}
println!("the set values are : {:?}",sets);
vec![]
Enter fullscreen mode Exit fullscreen mode

}