Got a lousy score, any clue on how to improve it ?
Question:
Given a non-empty array of integers nums, every element appears twice except for one. Find that single one.
You must implement a solution with a linear runtime complexity and use only constant extra space.
Example 1:
Input: nums = [2,2,1]
Output: 1
My sol:
use std::collections::HashMap;
impl Solution {
pub fn single_number(nums: Vec<i32>) -> i32 {
let mut hm = HashMap::new();
for val in nums.iter(){
match hm.insert(val,val){
Some(val) => hm.remove(&val),
Some(_) => hm.remove(&val),
None => hm.insert(val,val),
};
}
let vec:Vec<&i32> = hm.into_keys().collect();
*vec[0]
}
}
, fun time breaking the site though