题目描述 一个整型数组里除了两个数字之外,其他的数字都出现了偶数次。请写程序找出这两个只出现一次的数字。
C++ AC代码#include <iostream> #include <map> #include <vector> using namespace std; class Solution { public: void FindNumsAppearOnce(vector<int> data,int* num1,int *num2) { map<int,int> Map; for(int i = 0 ; i < data.size() ; i++){ Map[data[i]]++; } map<int,int>::iterator i; int cnt = 0; for(i = Map.begin() ; i != Map.end() ; i++){ cout<<i->first<<" "<<i->second<<endl; if(i->second == 1){ if(cnt == 0){ *num1 = i->first; } if(cnt == 1){ *num2 = i->first; break; } cnt++; } } } }; ---来自腾讯云社区的---AI那点小事剑指offer——数组中只出现一次的数字---AI那点小事
概要

微信扫一扫打赏
支付宝扫一扫打赏