剑指offer--35.数组中只出现一次的数字

时间限制:1秒 空间限制:32768K 热度指数:198150
本题知识点: 数组

题目描述

一个整型数组里除了两个数字之外,其他的数字都出现了两次。请写程序找出这两个只出现一次的数字。
class Solution {
    public:
        void FindNumsAppearOnce(vector<int> data,int* num1,int *num2) {
            for(int x:data) {
                if(count(data.begin(),data.end(),x) == 1) {
                    *num1 = x;
                    break;
                }
            }
            for(vector<int>::iterator it=find(data.begin(), data.end(), *num1); it!=data.end(); it++) {
                if(count(data.begin(),data.end(),*it) == 1 && *it != *num1) {
                    *num2 = *it;
                    break;
                }
            }
        }
};
原文地址:https://www.cnblogs.com/langyao/p/10625503.html