We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 13adfec commit 9efe879Copy full SHA for 9efe879
maximum-depth-of-binary-tree/YoungSeok-Choi.java
@@ -0,0 +1,35 @@
1
+import java.util.LinkedList;
2
+import java.util.Queue;
3
+
4
+// 시간복잡도 O(n)
5
+class Solution {
6
+ public int depth = 0;
7
+ public int maxDepth(TreeNode root) {
8
9
+ if(root == null) {
10
+ return depth;
11
+ }
12
13
+ Queue<TreeNode> q = new LinkedList<>();
14
+ q.add(root);
15
16
+ while(!q.isEmpty()) {
17
+ int size = q.size();
18
+ depth++;
19
20
+ for(int i = 0; i < size; i++) {
21
+ TreeNode p = q.poll();
22
23
+ if(p.right != null) {
24
+ q.add(p.right);
25
26
27
+ if(p.left != null) {
28
+ q.add(p.left);
29
30
31
32
33
34
35
+}
0 commit comments