The question description is so wrong


  • 0
    S

    The question description is all wrong. if there is no missing number, it wants to to return the n+1 number. Here is the solution.

    class Solution {
        public int missingNumber(int[] nums) {
            
            
    		Arrays.sort(nums);
    		
    		for(int i=0;i<nums.length;i++)
    		{
    			if(i!=nums[i])
    			{
            		return i;
    			}
    		}    
            return nums.length;
            
        }
    }
    

Log in to reply
 

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