Conversation
raejun92
approved these changes
Mar 9, 2026
Collaborator
There was a problem hiding this comment.
중간값이 해당 값이라는 것을 어떻게 생각해 내는지 신기하고 부럽습니다.
Collaborator
Author
There was a problem hiding this comment.
이런 스킬(?)은 양치기 영향이 있는듯 합니다. 예전에 백준에서 풀어본 기억이...ㅎ 처음 보는거였으면 전혀 몰랐을듯요
doitchuu
approved these changes
Mar 11, 2026
Member
doitchuu
left a comment
There was a problem hiding this comment.
MajorityElement 풀이 신박하고 좋네요 👍 고생하셨습니다 :)
| var majorityElement = function (nums) { | ||
| nums.sort((a, b) => a - b); | ||
| return nums[Math.floor(nums.length / 2)]; | ||
| }; |
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) 복잡도 계산
시간 복잡도: O(n)
공간 복잡도: O(1)
2) 접근 아이디어
단방향 연결 리스트의 next 방향을 모두 반대로 바꾸는 문제다.
각 노드의 포인터를 반대로 돌려주면 될 것 같다.
Linked List는 보통 이런 구조를 가지고 있는데,
이 구조에 의해,
이런 형태로 존재하게 된다. 이것을 뒤집어서
이렇게 표현되도록 하면 될 것 같다.
temp, curr을 선언해서 swap 하는 문제처럼 적용하면 될 것 같다.
3) 회고
저번에 Linked List 문제가 몇 번 나왔던 것 같은데 그거 아니였음 못풀었을 것 같다. Linked List를 뒤집는 과정에서 prev, curr, next 포인터를 어떻게 이동시키는지가 핵심이라는 것을 이해할 수 있었고, 포인터를 활용한 리스트 조작에 익숙해질 수 있었다.
2. Majority Element
1) 복잡도 계산
시간 복잡도: O(log n)
공간 복잡도: O(log n)
2) 접근 아이디어
오름차순 정렬하면 majority element는 항상 가운데 위치하게되는 특성이 있음을 활용했다.
3) 회고
다른 방식으로 풀었지만 공간복잡도를 O(1)로 풀 수 있는 방법이 있냐는걸 묻는걸 보아 사실 이 문제는
Boyer-Moore Voting Algorithm를 사용하는 풀이를 연습하도록 낸 문제인듯 하다. 이전에 백준 문제에서 풀어봤던 기억이 있는거 같은데 다시 새겨두어야겠다.Boyer-Moore Voting Algorithm의 핵심 로직은 아래와 같다.
majority element는 다른 모든 숫자보다 많기 때문에 가능한 현상이다.
3) 회고
알고리즘 문제 해결법에는 다양한 방법이 있고, 사람들마다 다양하게 푸는 것도 신기하다.
같은 문제라도 HashMap, 정렬, Boyer-Moore 등 다양한 풀이 방법이 있다는 점이 인상적이었고, 특히 공간 복잡도를 줄일 수 있는 Boyer-Moore 알고리즘을 알게 된 것이 좋았다.