策划方案免费网站,机械加工网上平台,wordpress 分享后下载地址,建设团购网站异或运算性质#xff0c;两个相等的数作异或运算得零#xff0c;任何数与零作异或运算保持不变 所以整个数组的异或和就是答案
class Solution:def singleNumber(self, nums: List[int]) - int:ans 0for i in nums:ans ^ ireturn ans一行代码#xff0c;reduce作累积操… 异或运算性质两个相等的数作异或运算得零任何数与零作异或运算保持不变 所以整个数组的异或和就是答案
class Solution:def singleNumber(self, nums: List[int]) - int:ans 0for i in nums:ans ^ ireturn ans一行代码reduce作累积操作
return reduce(xor, nums)