Merge pull request #650 from lakerschampions/master

更新了104. 二叉树的最大深度 JAVA版本
This commit is contained in:
程序员Carl
2021-08-26 11:16:04 +08:00
committed by GitHub

View File

@ -1528,6 +1528,29 @@ public:
```
Java
```Java
class Solution {
public int maxDepth(TreeNode root) {
if (root == null) return 0;
Queue<TreeNode> que = new LinkedList<>();
que.offer(root);
int depth = 0;
while (!que.isEmpty())
{
int len = que.size();
while (len > 0)
{
TreeNode node = que.poll();
if (node.left != null) que.offer(node.left);
if (node.right != null) que.offer(node.right);
len--;
}
depth++;
}
return depth;
}
}
```
Python