题目链接

求解二叉树的深度,延伸可见leetcode110题。

法一:dfs。

1     private int TreeDepth(TreeNode root) {
2         if(root == null) {
3             return 0;
4         }
5         int l = TreeDepth(root.left);
6         int r = TreeDepth(root.right);
7         return (l > r) ? (l + 1) : (r + 1);
8     }
View Code

相关文章:

  • 2021-11-26
  • 2022-12-23
  • 2022-12-23
  • 2021-04-02
猜你喜欢
  • 2021-07-21
  • 2021-07-31
  • 2022-01-18
  • 2022-02-21
  • 2022-12-23
  • 2022-12-23
  • 2021-09-15
相关资源
相似解决方案