Single Number
unknown
c_cpp
17 days ago
469 B
2
Indexable
Never
class Solution { public: int singleNumber(vector<int>& nums) { std::unordered_map<int,int> count; int size=nums.size(); for(int i=0;i<size;i++) { if(count.count(nums[i])) count[nums[i]]+=1; else count[nums[i]]=1; } for(auto it:count) { if(it.second==1) return it.first; } return 0; } };
Leave a Comment