原题地址

 

基本二叉树遍历

 

代码:

1 int minDepth(TreeNode *root) {
2         if (!root)
3             return 0;
4             
5         int l = root->left ? minDepth(root->left) : 0;
6         int r = root->right ? minDepth(root->right) : 0;
7         
8         return l * r > 0 ? min(l, r) + 1 : max(l, r) + 1;
9 }

 

相关文章:

  • 2021-09-23
  • 2021-08-14
  • 2021-09-17
  • 2021-11-17
  • 2022-12-23
  • 2021-05-22
猜你喜欢
  • 2021-12-21
  • 2021-04-17
  • 2021-08-21
  • 2021-11-02
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案