Skip to content

Commit

Permalink
Create 01-two-sum.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
xhofe committed Jul 1, 2023
1 parent 0384bdd commit 9870873
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions 2023/07/01-two-sum.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
impl Solution {
pub fn two_sum(nums: Vec<i32>, target: i32) -> Vec<i32> {
let mut map = std::collections::HashMap::new();
for (i, num) in nums.into_iter().enumerate() {
if let Some(&j) = map.get(&(target - num)) {
return vec![i as i32, j as i32];
}
map.insert(num, i);
}
vec![]
}
}

0 comments on commit 9870873

Please sign in to comment.