Conversation
raejun92
approved these changes
Feb 20, 2026
| var invertTree = function (root) { | ||
| if (root === null) return null; | ||
|
|
||
| [root.left, root.right] = [root.right, root.left]; |
Comment on lines
+6
to
+7
| invertTree(root.left); | ||
| invertTree(root.right); |
doitchuu
approved these changes
Feb 21, 2026
| } | ||
|
|
||
| return image; | ||
| }; |
Member
There was a problem hiding this comment.
오 정석적인 BFS 풀이네요 👍
초기 예외 케이스 적용이나 변수처리가 깔끔해서
읽기 좋은 거 같아요
| var invertTree = function (root) { | ||
| if (root === null) return null; | ||
|
|
||
| [root.left, root.right] = [root.right, root.left]; |
| var isAnagram = function (s, t) { | ||
| if (s.length !== t.length) return false; | ||
|
|
||
| const map = new Map(); |
Member
There was a problem hiding this comment.
s, t 각각 Map을 사용했었는데 하나로 해도좋은 거 같아요! 👍 💯
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. Invert Binary Tree
1) 복잡도 계산
시간 복잡도: O(n)
공간 복잡도: O(n)
2) 접근 아이디어
모든 노드에서 왼쪽 자식과 오른쪽 자식을 서로 바꿔주면 된다.
트리 전체를 한 번 순회하면서 swap을 수행하면 되므로 BFS보다는 DFS(재귀) 방식이 가장 직관적이라고 판단했다.
단계별 사고 과정
이 문제는 순회 방식(전위/후위)에 크게 영향을 받지 않는다.
각 노드에서 swap만 수행하면 되기 때문이다.
3) 회고
반복문이 3번 이상 중첩되거나 조건이 복잡해지면 못 푸는 경향이 있다. DFS 재귀 패턴에 더 익숙해질 필요가 있다고 느꼈다.
2. Valid Anagram
1) 복잡도 계산
시간 복잡도: O(n)
공간 복잡도: O(n)
2) 접근 아이디어
두 문자열이 애너그램인지 판단하려면 문자 구성과 개수가 완전히 동일해야 한다.
따라서 “문자 빈도”를 비교하면 된다고 생각했다.
단계별 사고 과정
정렬로도 풀 수 있지만 O(n log n)이라 해시맵을 사용하는 O(n) 방식이 더 효율적이다.
정렬로 하는 풀이
3) 회고
정렬 방식이 직관적이었지만, 이 문제의 본질은 “문자 빈도 비교”라는 걸 인지하는 게 더 중요하다고 느꼈다.
해시맵을 사용하는 문제는 “존재 여부 확인”인지 “개수 관리”인지 구분하는 연습이 필요하다.
3. Binary Search
1) 복잡도 계산
시간 복잡도: O(log n)
공간 복잡도: O(1)
2) 접근 아이디어
보통 정렬하고 시작하지만, 이 문제는 이미 정렬된 배열이 주어진다.
그리고 범위가 -10^4 < nums[i], target < 10^4로 1억이다. 즉, 선형 탐색이 아니라 이분 탐색을 사용해야 한다고 판단했다.
단계별 사고 과정
핵심은 “탐색 범위를 절반으로 줄인다”는 점이다.
3) 회고
이분 탐색은 알고리즘 자체는 단순하지만 경계 조건(left <= right)과 포인터 이동을 정확히 이해하는 게 중요하다고 느꼈다.
또한, 공부하면서 알게 된 점은 이분 탐색은 "정렬 + 단조성"이 있는 경우에만 사용 가능하다. 즉, 값이 증가하거나 감소하는 구조를 가진 배열 혹은 조건이 한쪽 방향으로 변하는 경우를 의미한다.
4. Flood Fill
1) 복잡도 계산
시간 복잡도: O(m x n)
공간 복잡도: O(m x n)
2) 접근 아이디어
시작 좌표(sr, sc)에서 출발해 start 지점의 색상과 같은 색을 가진 모든 연결된 영역을 새로운 색으로 바꾼다. 전형적인 BFS, DFS 탐색 문제.
단계별 사고 과정
3) 회고
처음에는 visited 배열을 따로 만들어야 하나 고민했지만,색을 바꾸는 행위 자체가 방문 체크가 된다는 점을 이해하고 나서 구조가 단순해졌다.
또한, 문제 풀이 후 다른 풀이 방식에 대해 탐색하다가 알게된 점이 있는데 shift()는 내부적으로 배열을 한 칸씩 당기기 때문에 queue 크기가 n일 때, 최악의 경우 O(n²)이 된다. 이러한 경우 head 포인터를 사용하면 O(n)으로 성능을 최적화할 수 있다.