close
題目: Given an integer n and an integer start. Define an array nums where nums[i] = start + 2*i (0-indexed) and n == nums.length. Return the bitwise XOR of all elements of nums. 解題: 題目要求將nums所有元素與0進行XOR,原本想說要轉二進再做XOR,沒想到直接XOR就可以了... Python Code:
class Solution: def xorOperation(self, n: int, start: int) -> int: ans = 0 for i in range(n): ans = ans^(start + i * 2) return ans
文章標籤
全站熱搜
留言列表