【打卡】牛客网:BM52 数组中只出现一次的两个数字

自己写的:

cpp 复制代码
#include <unordered_map>
class Solution {
public:
    /**
     * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
     *
     * 
     * @param nums int整型vector 
     * @return int整型vector
     */
    vector<int> FindNumsAppearOnce(vector<int>& nums) {
        // write code here
        map<int, int> hash;
        vector<int> res;
        for(int i = 0;i < nums.size(); i++){
            hash[nums[i]]++;
        }
        auto it = hash.begin();
        while(it != hash.end()){
            if(it->second == 1)
                res.push_back(it->first);
            it++; // 粗心,容易忘记
        }
        return res;
    }
};

模板的:

我用的是map,模板用的unordered_map。

模板最后对两个数进行排序。

相关推荐
mit6.8245 小时前
bfs|栈
算法
CoderYanger6 小时前
优选算法-栈:67.基本计算器Ⅱ
java·开发语言·算法·leetcode·职场和发展·1024程序员节
jllllyuz7 小时前
Matlab实现基于Matrix Pencil算法实现声源信号角度和时间估计
开发语言·算法·matlab
稚辉君.MCA_P8_Java7 小时前
DeepSeek 插入排序
linux·后端·算法·架构·排序算法
多多*7 小时前
Java复习 操作系统原理 计算机网络相关 2025年11月23日
java·开发语言·网络·算法·spring·microsoft·maven
.YM.Z8 小时前
【数据结构】:排序(一)
数据结构·算法·排序算法
Chat_zhanggong3458 小时前
K4A8G165WC-BITD产品推荐
人工智能·嵌入式硬件·算法
百***48078 小时前
【Golang】slice切片
开发语言·算法·golang
墨染点香9 小时前
LeetCode 刷题【172. 阶乘后的零】
算法·leetcode·职场和发展
做怪小疯子9 小时前
LeetCode 热题 100——链表——反转链表
算法·leetcode·链表