645. Set Mismatch

 1 static int wing=[]()
 2 {
 3     std::ios::sync_with_stdio(false);
 4     cin.tie(NULL);
 5     return 0;
 6 }();
 7 
 8 class Solution 
 9 {
10 public:
11     vector<int> findErrorNums(vector<int>& nums) 
12     {
13         int sz=nums.size();
14         vector<int> help(sz+1,0);
15         for(int i:nums)
16             help[i]++;
17         help[0]=1;
18         vector<int> res;
19         for(int i=0;i<sz+1;i++)
20         {
21             if(help[i]!=1)
22                 res.push_back(i);
23         }
24         if(help[res[0]]==0)
25             swap(res[0],res[1]);
26         return res;
27     }
28 };

扫一遍完事儿,简单粗暴

猜你喜欢

转载自www.cnblogs.com/zhuangbijingdeboke/p/9154999.html
今日推荐