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.
2 parents a290023 + 8a71f17 commit 39b11b2Copy full SHA for 39b11b2
2018.12.07-leetcode104/啦啦啦.md
@@ -0,0 +1,40 @@
1
+```java
2
+/**
3
+ * Definition for a binary tree node.
4
+ * public class TreeNode {
5
+ * int val;
6
+ * TreeNode left;
7
+ * TreeNode right;
8
+ * TreeNode(int x) { val = x; }
9
+ * }
10
+ */
11
+class Solution {
12
+ public int maxDepth(TreeNode root) {
13
+ if(root==null)return 0;
14
+ Queue<TreeNode> q = new LinkedList<>();
15
+ q.add(root);
16
+ int level = 0;
17
+ int next=0;
18
+ int last=1;
19
+ while(!q.isEmpty()){
20
+ TreeNode r = q.poll();
21
+ last--;
22
+ if(r.left!=null){
23
+ q.add(r.left);
24
+ next++;
25
+ }
26
+ if(r.right!=null){
27
+ q.add(r.right);
28
29
30
+
31
+ if(last==0){
32
+ level++;
33
+ last=next;
34
+ next=0;
35
36
37
+ return level;
38
39
+}
40
+```
0 commit comments