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
35 changes: 35 additions & 0 deletions maximum-depth-of-binary-tree/YoungSeok-Choi.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import java.util.LinkedList;
import java.util.Queue;

// 시간복잡도 O(n)
class Solution {
public int depth = 0;
public int maxDepth(TreeNode root) {

if(root == null) {
return depth;
}

Queue<TreeNode> q = new LinkedList<>();
q.add(root);

while(!q.isEmpty()) {
int size = q.size();
depth++;

for(int i = 0; i < size; i++) {
TreeNode p = q.poll();

if(p.right != null) {
q.add(p.right);
}

if(p.left != null) {
q.add(p.left);
}
}
}

return depth;
}
}
44 changes: 44 additions & 0 deletions merge-two-sorted-lists/YoungSeok-Choi.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// 시간복잡도 O(N + M)
class Solution {

public ListNode root = null;
public ListNode mergeTwoLists(ListNode list1, ListNode list2) {

while(list1 != null || list2 != null) {
int v1 = 9999;
int v2 = 9999;

if(list1 != null) {
v1 = list1.val;
}

if(list2 != null) {
v2 = list2.val;
}

if(v1 < v2) {
addNode(v1);
list1 = list1.next;
} else {
addNode(v2);
list2 = list2.next;
}
}

return root;
}

public void addNode (int val) {
if(root == null) {
root = new ListNode(val);
return;
}

ListNode now = root;
while(now.next != null) {
now = now.next;
}

now.next = new ListNode(val);
}
}