leetcode 日经贴,Cpp code -Minimum Depth of Binary Tree
2015-04-21 17:11
465 查看
Minimum Depth of Binary Tree
/** * Definition for binary tree * 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) { return 0; } if (!root->left && !root->right) { return 1; } int a = INT_MAX, b = INT_MAX; if (root->left) { a = minDepth(root->left) + 1; } if (root->right) { b = minDepth(root->right) + 1; } return min(a, b); } };
相关文章推荐
- leetcode 日经贴,Cpp code -Maximum Depth of Binary Tree
- LeetCode - Minimum Depth of Binary Tree
- Leetcode_Minimum Depth of Binary Tree
- leetcode 日经贴,Cpp code -Lowest Common Ancestor of a Binary Search 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 My Solution: 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 python
- leetcode第一刷_Minimum Depth of Binary Tree
- 【LeetCode】Minimum Depth of Binary Tree 解题报告
- [Leetcode][JAVA] Minimum Depth of Binary Tree && Balanced Binary Tree && Maximum Depth of Binary Tree
- LeetCode Minimum Depth of Binary Tree 最小深度二叉树
- [LeetCode] Minimum Depth of Binary Tree