0251-0260

251. Flatten 2D Vector $\star\star$

252. Meeting Rooms $\star$

253. Meeting Rooms II $\star\star$

254. Factor Combinations $\star\star$

255. Verify Preorder Sequence in Binary Search Tree $\star\star$

256. Paint House $\star$

257. Binary Tree Paths $\star$

258. Add Digits $\star$

259. 3Sum Smaller $\star\star$

260. Single Number III $\star\star$

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
class Solution {
 public:
  vector<int> singleNumber(vector<int>& nums) {
    vector<int> ans(2);

    int xor_ = accumulate(nums.begin(), nums.end(), 0, bit_xor<int>());
    xor_ &= -xor_;

    for (int num : nums) {
      if (num & xor_)
        ans[0] ^= num;
      else
        ans[1] ^= num;
    }

    return ans;
  }
};