Skip to content

[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 7 commits into from
Aug 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions maximum-depth-of-binary-tree/chordpli.py
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

max(right, left)로 root를 주면 어떻게 되나요? 자바스크립트에서는 노드끼리 비교가 되지 않았던 거 같았어요.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

원하시는 답변인지는 모르겠으나, 노드끼리 비교할경우 val까지 확인해야 비교가 되는 것 같습니다!

    root.left = TreeNode(9)
    root.right = TreeNode(9)

    print(root.left.val == root.right.val) True
    print(root.left == root.right) False

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
29 changes: 29 additions & 0 deletions merge-two-sorted-lists/chordpli.py
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

파이썬 코드도 리스트 노드도 되게 오랜만에 접하는데 확실히 파이썬의 가독성이 훨씬 나은 거 같네요. 수고하셨습니다!

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