题解 | #只出现一次的牛II#

只出现一次的牛II

https://www.nowcoder.com/practice/fde24d7d8f97467e91403d255243ee1c

#include <unordered_map>
class Solution {
public:
    /**
     * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
     *
     * 
     * @param nums int整型vector 
     * @return int整型vector
     */
    vector<int> findSingleCowsII(vector<int>& nums) {
        // write code here
        vector<int> ans;
        unordered_map<int, int> umap;
        for(auto i :nums){
            if(umap.find(i)==umap.end()){
                umap[i]=1;
            }
            else{
                umap.erase(i);
            }
        }
       for(auto & i : umap){
        ans.push_back(i.first);
       }
       sort(ans.begin(),ans.end());
       return ans;
    }
};

#23届找工作求助阵地#
全部评论

相关推荐

点赞 评论 收藏
转发
头像
不愿透露姓名的神秘牛友
04-16 22:40
投递美团等公司10个岗位
点赞 评论 收藏
转发
点赞 收藏 评论
分享
牛客网
牛客企业服务