Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
10 changes: 10 additions & 0 deletions maximum-depth-of-binary-tree/sm9171.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class Solution {
public int maxDepth(TreeNode root) {
if (root == null) {
return 0;
}
int leftDepth = maxDepth(root.left);
int rightDepth = maxDepth(root.right);
return Math.max(leftDepth, rightDepth) + 1;
}
}
20 changes: 20 additions & 0 deletions merge-two-sorted-lists/sm9171.java
Copy link
Contributor

Choose a reason for hiding this comment

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

안녕하세요, 작성하신 코드 잘 보았습니다! 더미 노드 사용해서 엣지 케이스까지 잘 구현하신 것 같아요. 그냥 개인적으로 궁금한 점이 있다면 자바에서 LinkedList를 제공하고 있는 걸로 아는데 직접 구현하신 이유가 있는지 여쭤보고 싶습니다!

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
class Solution {
public ListNode mergeTwoLists(ListNode list1, ListNode list2) {
ListNode dummy = new ListNode(-1);
ListNode node = dummy;

while (list1 != null && list2 != null) {
if (list1.val < list2.val) {
node.next = list1;
list1 = list1.next;
} else {
node.next = list2;
list2 = list2.next;
}
node = node.next;
}

node.next = list1 != null ? list1 : list2;
return dummy.next;
}
}