-
-
Notifications
You must be signed in to change notification settings - Fork 244
[hu6r1s] WEEK 12 Solutions #1939
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
c305d53
feat: Solve same-tree problem
hu6r1s d649798
feat: Solve remove-nth-node-from-end-of-list problem
hu6r1s 3214067
feat: number-of-connected-components-in-an-undirected-graph problem
hu6r1s 2615f35
feat: Solve non-overlapping-intervals problem
hu6r1s d3e9117
feat: Solve meeting-rooms problem
hu6r1s 3fa23d0
feat: Solve lowest-common-ancestor-of-a-binary-search-tree problem
hu6r1s 3fa02e1
feat: Solve kth-smallest-element-in-a-bst problem
hu6r1s 880f228
feat: Solve insert-interval problem
hu6r1s File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| # Definition for singly-linked list. | ||
| # class ListNode: | ||
| # def __init__(self, val=0, next=None): | ||
| # self.val = val | ||
| # self.next = next | ||
| class Solution: | ||
| def removeNthFromEnd(self, head: Optional[ListNode], n: int) -> Optional[ListNode]: | ||
| length = 0 | ||
| node = head | ||
| while node: | ||
| length += 1 | ||
| node = node.next | ||
|
|
||
| dummy = ListNode(None, head) | ||
| node = dummy | ||
| for _ in range(length - n): | ||
| node = node.next | ||
|
|
||
| node.next = node.next.next | ||
| return dummy.next |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| # Definition for a binary tree node. | ||
| # class TreeNode: | ||
| # def __init__(self, val=0, left=None, right=None): | ||
| # self.val = val | ||
| # self.left = left | ||
| # self.right = right | ||
| class Solution: | ||
| def isSameTree(self, p: Optional[TreeNode], q: Optional[TreeNode]) -> bool: | ||
| if not p and not q: | ||
| return True | ||
| if not p or not q: | ||
| return False | ||
| if p.val != q.val: | ||
| return False | ||
| return self.isSameTree(p.left, q.left) and self.isSameTree(p.right, q.right) | ||
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.
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.
2번째 if문과 3번째 if문을 합쳐도 될 거 같아 보이는데, 이렇게는 안 되나요?
물론 가독성은 분리했을 때 더 나은 거 같긴 해요.