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     int singleNumber(vector<int>& nums) 
12     {
13         int res=0;
14         for(int i:nums)
15             res^=i;
16         return res;
17     }
18 };

核心思想是位操作的异或。0^N=N    N^N=0

找出单身汉,用0去勾搭。成对的勾搭完了还是0,单身汉勾搭完了就是单身那个。

posted on 2018-05-21 10:46  高数考了59  阅读(94)  评论(0)    收藏  举报