Given an array containing n distinct numbers taken from 0, 1, 2, ..., n
, find the one that is missing from the array.
For example,
Given nums = [0, 1, 3]
return 2
Analysis: This question is also a question to make use of the XOR bit manipulation to get rid of the repeated integer in a array
code
public class Solution {
public int missingNumber(int[] nums) {
int length = nums.length;
int result = 0;
for(int i = 0; i < length; i++){
result ^= nums[i] ^ i + 1;
}
return result;
}
}