Java Solution & 12 lines


  • 0
    B
        public int firstMissingPositive(int[] nums) {
            Arrays.sort(nums);
            int aim = 1;
            for(int i = 0; i < nums.length; i++){
                if(aim > nums[i]) continue;
                else if(aim == nums[i]) aim++;
                else return aim;
            }
            return aim;
        }
    }

Log in to reply
 

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