4 Line Java solution O(1) space O(n) time only use add , minus and traversal


  • 0
    W
       public int missingNumber(int[] nums) {
        	int answer = 0 , i=0;
        	for( ; i<nums.length; i++)
        		answer+=(i-nums[i]);
            return answer+i;
        }
    

Log in to reply
 

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