-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmain.rs
More file actions
32 lines (28 loc) · 768 Bytes
/
main.rs
File metadata and controls
32 lines (28 loc) · 768 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
fn main() {
assert_eq!(Solution::contains_duplicate(vec![1,2,3,1]), true);
}
struct Solution {}
impl Solution {
pub fn contains_duplicate(nums: Vec<i32>) -> bool {
use std::collections::HashMap;
let mut map: HashMap<i32, i32> = HashMap::new();
for i in nums {
if map.contains_key(&i) {
return true;
} else {
map.insert(i, 1);
}
}
false
}
}
#[cfg(test)]
mod test {
use crate::*;
#[test]
fn basic() {
assert_eq!(Solution::contains_duplicate(vec![1,2,3,1]), true);
assert_eq!(Solution::contains_duplicate(vec![1,2,3,4]), false);
assert_eq!(Solution::contains_duplicate(vec![1,1,1,3,3,4,3,2,4,2]), true);
}
}