給你兩個整數,n 和 start 。數組 nums 定義爲:nums[i] = start + 2*i(下標從 0 開始)且 n == nums.length 。

給你兩個整數,n 和 start 。
數組 nums 定義爲:nums[i] = start + 2*i(下標從 0 開始)且 n == nums.length 。
請返回 nums 中所有元素按位異或(XOR)後得到的結果。

class Solution {

    public int xorOperation(int n, int start) {

        int res=0;

        for(int i=0;i<n;i++){

            res^=(start+2*i);

        }

        return res;

    }

}

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章