Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fc7a5f7

Browse files
committed
save
1 parent 027cb6c commit fc7a5f7

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

rust/0217-contains-duplicate.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,13 @@ use std::collections::HashSet;
33
impl Solution {
44
pub fn contains_duplicate(nums: Vec<i32>) -> bool {
55
let mut map = HashSet::new();
6-
7-
for &n in nums.iter(){
86

9-
if map.contains(&n){
10-
return true;
7+
for n in nums {
8+
if !map.insert(n){
9+
return true;
1110
}
12-
13-
map.insert(n);
14-
};
15-
11+
}
12+
1613
false
1714
}
1815
}

0 commit comments

Comments
 (0)