1 2 3 4 5 6 7 8 9 10 11 12 13 14
| class Solution { public: int sumXor(int x) { if (x % 4 == 0) return x; if (x % 4 == 1) return 1; if (x % 4 == 2) return x + 1; return 0; } int xorOperation(int n, int start) { int s = start >> 1, e = n & start & 1; int ret = sumXor(s - 1) ^ sumXor(s + n - 1); return ret << 1 | e; } };
|