Missing Number(异或)
Given an array containingndistinct numbers taken from0, 1, 2, ..., n
, find the one that is missing from the array.
Example 1:
Example 2:
Note: Your algorithm should run in linear runtime complexity. Could you implement it using only constant extra space complexity?
分析
异或 x=x^index^nums[index] 完美数组的数组 index=nums[index]
或者n(n+1)//2 记得要用//2
Last updated