-
-
Notifications
You must be signed in to change notification settings - Fork 247
[chordpli] WEEK 04 solutions #1832
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 all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
598ae27
feat: 1week
chordpli 5a8364b
feat: 2week (#2)
chordpli ee9872e
3week
chordpli 282670f
Merge branch 'DaleStudy:main' into main
chordpli 66e51b0
style: lint
chordpli 9ebe4bc
Merge branch 'DaleStudy:main' into main
chordpli fbe9a3f
feat: 4 weeks
chordpli 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,9 @@ | ||
class Solution: | ||
def maxDepth(self, root: Optional[TreeNode]) -> int: | ||
if not root: | ||
return 0 | ||
|
||
right = self.maxDepth(root.right) | ||
left = self.maxDepth(root.left) | ||
|
||
return max(right, left) + 1 |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 파이썬 코드도 리스트 노드도 되게 오랜만에 접하는데 확실히 파이썬의 가독성이 훨씬 나은 거 같네요. 수고하셨습니다! |
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,29 @@ | ||
# class ListNode: | ||
# def __init__(self, val=0, next=None): | ||
# self.val = val | ||
# self.next = next | ||
|
||
|
||
class Solution: | ||
def mergeTwoLists(self, list1: Optional[ListNode], list2: Optional[ListNode]) -> Optional[ListNode]: | ||
if not list1: | ||
return list2 | ||
|
||
if not list2: | ||
return list1 | ||
|
||
merge_node: ListNode = ListNode() | ||
current = merge_node | ||
|
||
while list1 and list2: | ||
if list1.val < list2.val: | ||
current.next = list1 | ||
list1 = list1.next | ||
else: | ||
current.next = list2 | ||
list2 = list2.next | ||
|
||
current = current.next | ||
|
||
current.next = list1 or list2 | ||
return merge_node.next |
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.
max(right, left)로 root를 주면 어떻게 되나요? 자바스크립트에서는 노드끼리 비교가 되지 않았던 거 같았어요.
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.
원하시는 답변인지는 모르겠으나, 노드끼리 비교할경우 val까지 확인해야 비교가 되는 것 같습니다!