题解 | #牛的编号异或问题#
牛的编号异或问题
https://www.nowcoder.com/practice/b8139d2af0f64e6489f69cb173f170c1
题目考察的知识点:异或
题目解答方法的文字分析:异或left+1~right区间的值
本题解析所用的编程语言:c++
class Solution {
public:
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param left int整型
* @param right int整型
* @return int整型
*/
int rangeBitwiseXor(int left, int right) {
// write code here
int n = 0;
while (left < right)
{
++left;
n ^= left;
}
return n;
}
};


