Short. O(1) space complexity Java solution(2ms).


  • 0
    O
        public int missingNumber(int[] nums) {
        	int tmp = 0;
        	for(int i = 0; i <= nums.length; i++){
        	    tmp ^= i;
        	}
        	for(int i: nums){
        	    tmp ^= i;
        	}
            return tmp;
        }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.