O
问题
解决方案
代码
class Solution {
public:
vector<int> FindNumsAppearOnce(vector<int>& array) {
unordered_map<int, int> need;
vector<int> ans;
for(int i = 0; i< array.size();i++){
need[array[i]]++;
}
for (unordered_map<int, int>::iterator it = need.begin(); it != need.end(); it++) {
if((*it).second < 2 ) ans. push_back((*it).first);
}
compare(ans);
return ans;
}
void compare(vector<int>& ans){
if(ans[0]>ans[1]){
int temp = ans[0];
ans[0] = ans[1];
ans[1] = temp;
}
}
};
总结与反思
- 这道题的题目感觉有点问题。 已改是大于等于2 , 测试给的四个1也算重复。