217. Contains Duplicate
Check if any value appears at least twice in nums.
HashSet approach:
#![allow(unused)]
fn main() {
pub fn contains_duplicate(nums: Vec<i32>) -> bool {
let mut unique: HashSet<i32> = HashSet::with_capacity(nums.len());
for num in nums {
if !unique.insert(num) {
return true;
}
}
false
}
}