首页 > 代码库 > 260. Single Number III

260. Single Number III

 1 class Solution { 2 public: 3     vector<int> singleNumber(vector<int>& nums) { 4         int num = 0; 5         for (const auto& item : nums) { 6             num ^= item; 7         } 8         int cmp = 1, count = 0; 9         while (!(num & cmp)) {10             cmp <<= 1; ++count;11         }12         int num1 = 0;13         for (const auto& item : nums) {14             if (item & cmp) num1 ^= item;15         }16         int num2 = num ^ num1;17         return vector<int> {num1, num2};18     }19 };

 

260. Single Number III