My organic solution, maybe slow, but it is really easy to understand.


  • 0
    C
    public class Solution {
        public int missingNumber(int[] nums) {
            Arrays.sort(nums);
            if(nums[0] > 0) return nums[0]-1;
            int index = 0;
            
            while(index < nums.length-1){
                if(nums[index+1] - nums[index] ==1){
                    index++;
                }
                
                else{
                    return nums[index] + 1;
                }
            }
            
            return nums[index] + 1;
        }
    }
    
    

Log in to reply
 

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