/** * @param{number[]} nums * @return{number} */varmissingNumber=function(nums) {let ans =nums.length;for (let i =0; i <nums.length; i++) { ans = ans^i^nums[i]; }return ans;};
time: O(N)
space: O(1)
/** * @param{number[]} nums * @return{number} */varmissingNumber=function(nums) {let sum =0;let total =0;for (let i =0; i <nums.length; i++) { total += i +1; sum += nums[i]; }return total - sum;};