-
Notifications
You must be signed in to change notification settings - Fork 120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[EGON] Week11 Solutions #554
Conversation
root = unionFind.find(0) | ||
for i in range(1, n): | ||
if unionFind.find(i) != root: | ||
return False |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이 부분은 edges의 길이가 N-1개 미만인지 아닌지로 체크할 수도 있지만, union-find 쓰는데 통일해서 사용했습니다
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lymchgmk 님 지난주도 고생 많으셨습니다!
이제 정말 거의 끝이 보이는데, 이번 주도 잘 부탁드립니다!
""" | ||
def solve_union_find(self, n: int, edges: List[List[int]]) -> bool: | ||
|
||
class UnionFind: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
오 유니온파인드를 클래스로 만들어두고 풀이하셨네요
LintCode 로그인이 안되어서 https://neetcode.io/problems/valid-tree에서 실행시키고 통과만 확인했습니다. | ||
|
||
Runtime: ? ms (Beats ?%) | ||
Time Complexity: O(max(m, n)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
설명을 자세히 적어주셔서 좋네요! 감사합니다!
다만 이 문제의 경우 edges.length = n-1이라는 조건이 있으니, O(n)으로 단순화 할 수 있을것으로 보입니다!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
간선의 총 갯수가 n-1개가 아닌 케이스가 있었던 것 같은데... 예를 들어 서로 분리된 유효한 트리 2개인 경우나, example2의 TC도 있었습니다.
Input: n = 5 edges = [[0, 1], [1, 2], [2, 3], [1, 3], [1, 4]]
Output: false.
elif new_e < s: | ||
if new_s != -1 and new_e != -1: | ||
result.append([new_s, new_e]) | ||
new_s = new_e = -1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-1이 뭔가 했네요.
굉장히 스마트한 풀이이긴 한데, 주석이나 변수명으로 안내를 해주시면 좀 더 좋을 것 같아요!
Space Complexity: O(n) | ||
> 역방향 링크드 리스트인 backward를 생성하는데, backward의 길이는 원본 링크드 리스트의 길이와 같으므로 O(n) | ||
""" | ||
def solve(self, head: Optional[ListNode]) -> None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
오 다른분들과 다른 새로운 풀이네요!
잘 보고 갑니다!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
backward를 생성하는 풀이방법 충분히 납득되는 풀이방법이네요.👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이번주도 수고많으셨습니다! 🙂
Space Complexity: O(n) | ||
> 역방향 링크드 리스트인 backward를 생성하는데, backward의 길이는 원본 링크드 리스트의 길이와 같으므로 O(n) | ||
""" | ||
def solve(self, head: Optional[ListNode]) -> None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
backward를 생성하는 풀이방법 충분히 납득되는 풀이방법이네요.👍
답안 제출 문제
체크 리스트
In Review
로 설정해주세요.