Bunker

[hard] 41. First Missing Positive 본문

Algorithms/Leetcode

[hard] 41. First Missing Positive

_Ishmael 2022. 7. 25. 21:54

문제

https://leetcode.com/problems/first-missing-positive/

 

First Missing Positive - LeetCode

Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.

leetcode.com

풀이

1) Merge Sort를 이용하여 리스트에 있는 숫자를 먼저 오름차순으로 정리

2) 가장 작은 수를 1로 설정하고, 

- 0보다 작거나 같은 element는 skip

- 현재의 가장 작은 수와 동일한 element가 나올 경우, 작은 수를 +1

- 현재의 가장 작은 수보다 큰 element가 나올 경우, for-loop 종료

 

고찰

Merge Sort,,, 외워야겠지?

그리고, 성능이 그렇게 좋지 않다.

 

코드

https://github.com/suy-lee/algorithm/blob/master/LeetCode_FirstMissingPositive.c

 

레퍼런스

https://noname122.tistory.com/38

'Algorithms > Leetcode' 카테고리의 다른 글

[easy] 771. Jewels and Stones  (0) 2022.08.03
[medium] 54. Spiral Matrix  (0) 2022.08.02
[medium] 238. Product of Array Except Self  (0) 2022.07.25
Youtube Searching Script (Javascript)  (0) 2018.05.07