您的位置 首页 > 腾讯云社区

剑指offer——数组中只出现一次的数字---AI那点小事

概要

题目描述 一个整型数组里除了两个数字之外,其他的数字都出现了偶数次。请写程序找出这两个只出现一次的数字。

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那点小事

关于作者: 瞎采新闻

这里可以显示个人介绍!这里可以显示个人介绍!

热门文章

留言与评论(共有 0 条评论)
   
验证码: