[LintCode] Find the Missing Number
public int findMissing(int[] nums) { // write your code here if(nums.length == 0 || nums == null) return 0; int missing = 0; int n = nums.length; for(int i = 0; i <= n; i++) { missing^=i; } // xor [0,n] for(int i : nums) missi raneng ^= i;//xor i, i in nums return missing; }
Leave A Comment