1486. XOR Operation in an Array

1
2
3
4
5
6
7
8
9
10
11
class Solution {
public int xorOperation(int n, int start) {
int ans = 0;

for (int i = 0; i < n; i++) {
ans ^= start + 2 * i;
}

return ans;
}
}

Reference

1486. XOR Operation in an Array