Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
superj80820 committed Apr 1, 2024
1 parent 24c19db commit 33edeff
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
15 changes: 15 additions & 0 deletions neetcode/0001-two-sum.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
use std::collections::HashMap;

impl Solution {
pub fn two_sum(nums: Vec<i32>, target: i32) -> Vec<i32> {
let mut check = HashMap::new();
for (idx, val) in nums.iter().enumerate() {
if let Some(&idx2) = check.get(&(target - val)) {
return vec![idx as i32, idx2 as i32];
} else {
check.insert(val, idx as i32);
}
}
unreachable!()
}
}
15 changes: 15 additions & 0 deletions neetcode/0217-contains-duplicate.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
use std::collections::HashSet;

impl Solution {
pub fn contains_duplicate(nums: Vec<i32>) -> bool {
let mut check = HashSet::new();
for val in nums.iter() {
if check.contains(val) {
return true;
} else {
check.insert(val);
}
}
return false;
}
}

0 comments on commit 33edeff

Please sign in to comment.