递归的话没什么好讲的
class Solution {
public int maxDepth(TreeNode root) {
if (root == null) {
return 0;
}
return Math.max(maxDepth(root.left),maxDepth(root.right))+1;
}
}
非递归可以用层序遍历,类似于BFS,