Given an unsorted integer array nums, find the smallest missing positive integer.
Example 1:
Input: nums = [1,2,0]
Output: 3
Example 2:
Input: nums = [3,4,-1,1]
Output: 2
Example 3:
Input: nums = [7,8,9,11,12]
Output: 1
(요약) 배열에 없는 가장 작은 양의 정수를 구하라.
var firstMissingPositive = function(nums) { let min = 1; while(nums.includes(min)) { min++; } return min; };
가장 작은 양의 정수는
1
이니까 우선1
을 세팅하고,nums
배열에 있으면 1씩 증가시켜서 있는지 확인하다가 없으면 그 숫자를return
.좀 비효율적인거 같아서 다른 사람풀이를 보니 코드가 긴데도 처리가 빠른 코드가 여러가지가 있다.