Conversation
doitchuu
previously approved these changes
Feb 23, 2026
| MyQueue.prototype.empty = function () { | ||
| if (this.node === null) return true; | ||
| else return false; | ||
| }; |
Member
There was a problem hiding this comment.
링크드 리스트로 푸셨군요..!
저도 풀이 과정 힌트 받아가면서 다시 풀어보았는데
아래 풀이도 참고하기 좋은 것 같아 공유드려요
| } | ||
|
|
||
| return false; | ||
| }; |
Member
There was a problem hiding this comment.
오 값을 바꿔주는 방식도 있군요..!
저는 방문을 체크했는데, 방문 체크 말고도
토끼와 거북이 처럼 2개와 1개(head.next.next와 head.next) 씩 next를 비교하는 방법도 신박했던 거 같아요
doitchuu
approved these changes
Feb 28, 2026
sik9252
approved these changes
Mar 2, 2026
| * @return {boolean} | ||
| */ | ||
| MyQueue.prototype.empty = function () { | ||
| if (this.node === null) return true; |
Collaborator
There was a problem hiding this comment.
링크드 리스트로 푸는 방법도 좋지만(?) 지금 코드 구조상 생성자에서 this.node = new ListNode(undefined)로 항상 객체를 만들기 때문에, this.node가 null이 되는 흐름이 없지 않을까요! 그래서 null로는 empty 판단이 안될 수도 있을 것 같아요 (그냥 갑자기 생각난 부분..)
| q, p 중 더 높은 위치(더 깊은 노드)에 있는 노드를 부모로 이동시키는 방식으로 풀이했다. | ||
|
|
||
| 트리의 자식에서 부모로 가는 방법이 떠오르지 않았다. 그래서 따로 q, p의 위치를 찾고 부모를 찾는 함수를 만들어서 풀이했다. | ||
| */ |
Collaborator
There was a problem hiding this comment.
이 문제는 BST이기 때문에, “왼쪽 < root < 오른쪽”이라는 정렬 특성을 활용하면 더 쉽게 풀 수 있을 것 같네용. 저도 이번에 처음 알았지만 p와 q가 둘 다 root보다 작으면 왼쪽으로, 둘 다 크면 오른쪽으로 내려가면 되며, 갈라지는 지점이 LCA가 된다는 특성을 가지고 있대요!
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. Linked List Cycle
1) 복잡도 계산
시간 복잡도: O(n)
2) 접근 아이디어
3) 회고
노드의 값을 바꿔주는 방식이 다소 비효율적이긴 하지만, 다른 방법이 생각나지 않아 풀이했다.
2. Implement Queue using Stacks
1) 복잡도 계산
시간 복잡도: push, pop, peek, empty 모두 O(1)
2) 접근 아이디어
3) 회고
링크드 리스트 문제를 풀면서 링크드 리스트로 구현을 하려고 했는데 실패했다.
문제에서 스택을 2개 사용하라고 했는데, 어떻게 스택을 이용해야 하는지 감이 잡히지 않았다.
당연히 Array의 매서드를 사용하면 안될 줄 알았는데 풀이를 보니 Array의 매서드를 사용해서 풀이하였다.
3. Lowest Common Ancestor of a Binary Search Tree
1) 복잡도 계산
시간 복잡도: O(n²) — n은 트리의 노드 수
2) 접근 아이디어
3) 회고
트리의 자식에서 부모로 가는 방법이 떠오르지 않았다. 그래서 따로 q, p의 위치를 찾고 부모를 찾는 함수를 만들어서 풀이했다.
4. Balanced Binary Tree
1) 복잡도 계산
시간 복잡도: O(n) — n은 트리의 노드 수
2) 접근 아이디어
3) 회고
문제 이해가 잘 안됐다. 왼쪽과 오른쪽 차이가 1이란 게 루트에서 나오는 왼쪽과 오른쪽만 생각했다.
하지만, 트리의 모든 노드에서 왼쪽과 오른쪽 차이가 1이 되어야 한다는 조건으로 내가 푼 풀이에는 문제가 있다.