java solution


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

Log in to reply
 

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