0到n-1就这样
class Solution {
public:
int xorOperation(int n, int start) {
//先求出每一位,然后依次异或,异或^相同为0,不同为1,所以一开始和0异或
int res = 0;
//下标从0开始,到n-1很重要
for(int i = 0; i < n; ++i){
res ^= (start + 2*i);
}
return res;
}
};