LC 104 //递归 // 0 ms(100.00%) 38.6 MB(10.80) class Solution { public int maxDepth(TreeNode root) { if (root==null) return 0; return Math.max(maxDepth(root.left),maxDepth(root.right))+1; } } //迭代 //可以利用层级遍历的思想 和103类似 但只是记录层数不做别的操作 //空间占用率更高 但树很深的时候可能更好