[Leetcode - Easy] Third Maximum Number #12
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
문제
풀이
nums
배열을 set으로 변환한다.uniqueNums
)로 변환한다.uniqueNums
를 내림차순으로 정렬한다.uniqueNums
의 원소의 갯수가 3개 이하라면 첫 번째 인덱스의 값을 반환하고, 그렇지 않다면 세 번째 인덱스의 값을 반환한다.어려웠던 점
알게된 점
사실 이 문제를 알고리즘에 작성한 이유가 문제 풀이가 어려워서라기 보다는 알게된 점이 커서 작성하게 되었다.
1. Set 내장 메서드 사용이 기억이 안난다면 Array로 변환하기
Set 내장 메서드를 단순히 Array로 변환할 수 있는 이유는 자바스크립트의 Set, Map, 배열, 문자열이 모두 이터러블 객체이기 때문.
2. 자바스크립트의 Set은 순서를 보장한다