Java using XOR O(n)


  • 0
    L
    public int singleNumber(int[] nums) {
            if(nums==null){
        		return -1;
        	}
            int i = 0;
            int result = 0;
            while(i<nums.length){
            	result ^= nums[i];
            	i++;
            }
            
            return result;
        }
    

Log in to reply
 

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