LeetCode-Minimum Depth of Binary Tree
2014-09-12 10:23
316 查看
//注意{1,2}是2。。。挨坑了
int depth(TreeNode *root, int sum) { if(root->left==NULL && root->right==NULL) return sum; if(root->left==NULL) return depth(root->right,sum+1); if(root->right==NULL) return depth(root->left,sum+1); int left=0; int right=0; if(root->left!=NULL) left=depth(root->left,sum+1); if(root->right!=NULL) right=depth(root->right,sum+1); return left>right?right:left; } int minDepth(TreeNode *root) { if(root==NULL) return 0; return depth(root, 1); }
相关文章推荐
- [面试真题] LeetCode:Minimum Depth of Binary Tree
- LeetCode:Minimum Depth of Binary Tree
- [leetcode刷题系列]Minimum Depth of Binary Tree
- LeetCode: Minimum Depth of Binary Tree
- 【leetcode】Minimum Depth of Binary Tree
- [Leetcode] Minimum Depth of Binary Tree
- leetcode 31: Minimum Depth of Binary Tree
- leetcode--Minimum Depth of Binary Tree
- [LeetCode] Minimum Depth of Binary Tree - BFS
- LeetCode-Minimum Depth of Binary Tree
- 【LeetCode with Python】 Minimum Depth of Binary Tree
- [leetcode]Minimum Depth of Binary Tree
- Leetcode: Minimum Depth of Binary Tree
- [LeetCode 111] - 二叉树的最小深度 (Minimum Depth of Binary Tree)
- leetcode: Minimum Depth of Binary Tree
- 【leetcode】Minimum Depth of Binary Tree
- [LeetCode]Minimum Depth of Binary Tree
- LeetCode_Minimum Depth of Binary Tree
- LeetCode题目笔记(一) -- Minimum Depth Of Binary Tree
- leetcode -- Minimum Depth of Binary Tree