leetcode 111. Minimum Depth of Binary Tree
2016-08-21 15:33
387 查看
/** * 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 dep; void dfs(TreeNode*root,int d){ if(d >= dep || root == NULL) return ; if(root->left == NULL && root->right == NULL){ dep = d; return ; } dfs(root->left,d+1); dfs(root->right,d+1); } int minDepth(TreeNode* root) { dep = 1000000000; if(root == NULL) return 0; dfs(root,1); return dep; } };
相关文章推荐
- LEETCODE —— Binary Tree的3 题 —— 3种非Recursive遍历
- 【LeetCode】111. Minimum Depth of Binary Tree
- leetcode解题报告:104. Maximum Depth of Binary Tree
- leetcode 每日一题 111. Minimum Depth of Binary Tree
- Leetcode Everyday: 104. Maximum Depth of Binary Tree
- <LeetCode OJ> Invert Binary Tree【226】
- 【LeetCode】111. Minimum Depth of Binary Tree (2 solutions)
- LeetCode543. Diameter of Binary Tree
- [leetcode]111. Minimum Depth of Binary Tree
- leetcode 654. Maximum Binary Tree
- [Leetcode] Binary tree -- 501. Find Mode in Binary Search Tree
- LeetCode-104. Maximum Depth of Binary Tree
- 第十八周:[Leetcode]111. Minimum Depth of Binary Tree
- LeetCode 226. Invert Binary Tree (反转二叉树)
- [Leetcode] Binary tree--653. Two Sum IV
- leetcode记录 104. Maximum Depth of Binary Tree
- LeetCode *** 111. Minimum Depth of Binary Tree
- Leetcode 104. Maximum Depth of Binary Tree
- leetcode 104. Maximum Depth of Binary Tree
- 【Leetcode】111. Minimum Depth of Binary Tree