111. Minimum Depth of Binary Tree
来源:互联网 发布:java jlabel 图片 编辑:程序博客网 时间:2024/06/06 18:04
参考上一题求深度,记得如果有一边是null,就要返回另一边的深度+1!!!这个不能够省略,否则就wa
/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */class Solution {public: int minDepth(TreeNode* root) { if(root == NULL) return 0; if(root -> left == NULL && root -> right == NULL) return 1; int dl = minDepth(root -> left); int dr = minDepth(root -> right); if(dl == 0) return dr + 1; if(dr == 0) return dl + 1; return dl > dr ? dr + 1: dl + 1; }};
0 0
- LeetCode 111. Minimum Depth of Binary Tree
- [LeetCode]111.Minimum Depth of Binary Tree
- 【LeetCode】111.Minimum Depth of Binary Tree
- [Leetcode] 111. Minimum Depth of Binary Tree
- 111.Minimum Depth of Binary Tree
- 111. Minimum Depth of Binary Tree
- [leetcode] 111. Minimum Depth of Binary Tree
- 111. Minimum Depth of Binary Tree
- 111. Minimum Depth of Binary Tree
- 111. Minimum Depth of Binary Tree
- 111. Minimum Depth of Binary Tree LeetCode
- 111. Minimum Depth of Binary Tree
- 111. Minimum Depth of Binary Tree
- 【LeetCode】111. Minimum Depth of Binary Tree
- 111. Minimum Depth of Binary Tree
- 111. Minimum Depth of Binary Tree
- LeetCode *** 111. Minimum Depth of Binary Tree
- 111. Minimum Depth of Binary Tree
- 1st round, 283 moveZeroes
- xss (跨站脚本攻击)教程
- Leetcode 202. Happy Number
- xss(跨站脚本攻击)教程
- 2016年总结:教师路的开启,爱情味的初尝 (下)
- 111. Minimum Depth of Binary Tree
- 1st round, 325 maxSubArrayLen
- 浅谈CSRF攻击方式
- 112. Path Sum
- 113. Path Sum II
- 114. Flatten Binary Tree to Linked List
- 115. Distinct Subsequences
- 116. Populating Next Right Pointers in Each Node
- 117. Populating Next Right Pointers in Each Node II