Merged
Conversation
sik9252
reviewed
Mar 9, 2026
| for (let i = 0; i < nums.length; i++) { | ||
| map.set(nums[i], (map.get(nums[i]) || 0) + 1); | ||
|
|
||
| if (map.get(nums[i]) > nums.length / 2) { |
Collaborator
There was a problem hiding this comment.
Map으로 개수를 세면서 과반수를 넘는 순간 바로 반환하는 방식 좋은 것 같아요~
sik9252
reviewed
Mar 9, 2026
Collaborator
There was a problem hiding this comment.
prev, current, next 포인터를 사용한 정석적인 반복 풀이로 잘 구현하신 것 같습니다!
sik9252
approved these changes
Mar 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
이렇게 풀었어요
1. Reverse Linked List
1) 복잡도 계산
2) 접근 아이디어
3) 회고
포인터가 반복마다 어디를 가리키는지 추적하는 과정이 가장 어려웠다. 1 → 2 → 3 → 4 → null에서 prev = null, current = 1로 시작해 next = current.next, current.next = prev를 수행하면 1 → null과 2 → 3 → 4로 분리된다. 이 과정을 current가 null이 될 때까지 반복하면 링크 방향이 완전히 뒤집혀 4 → 3 → 2 → 1 → null이 된다. 반복 종료 시점에 prev는 새 head(4), current는 null을 가리키므로 반환값은 prev가 맞다.
2. Majority Element
1) 복잡도 계산
2) 접근 아이디어
3) 회고
Boyer–Moore Voting Algorithm을 새로 배웠다. 서로 다른 값을 만나면 표를 상쇄하고, cnt가 0이 되면 후보를 교체하는 방식이라 로직이 간결했다. 다수 원소가 반드시 존재한다는 조건에서 마지막 후보가 정답이 되는 이유도 명확하게 이해됐다.
다른 사람 풀이:
다른 사람 풀이 핵심: 풀이 흐름을 단계별로 분리해 조건 확인과 상태 갱신을 명확히 나눈 점이 핵심이었다.
내 생각: cnt가 0이 될 때 후보를 교체하는 규칙이 단순해서 구현 실수를 줄이기 좋았다. 다음에는 해시맵 풀이와 투표 알고리즘을 같이 구현해 복잡도와 가독성을 비교해 보려고 한다.