[LeetCode] Minimum Depth of Binary Tree - DFS
来源:互联网 发布:网络三大奇书四大神书 编辑:程序博客网 时间:2024/05/01 19:25
/** * 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) { // Start typing your C/C++ solution below // DO NOT write int main() function if (!root) return 0; int left = minDepth(root->left); int right = minDepth(root->right); if (root->left && root->right) return min(left, right) + 1; else return left + right + 1; }};
Small Case: 8ms
Large Case: 92ms
Time: O(n)
Space: O(1)
DFS version.
- [LeetCode] Minimum Depth of Binary Tree - DFS
- leetcode dfs Minimum Depth of Binary Tree
- [leetcode][tree][dfs] Minimum Depth of Binary Tree
- LeetCode 111 Minimum Depth of Binary Tree (DFS)
- Leetcode 111 - Minimum Depth of Binary Tree(dfs)
- LeetCode 111 Minimum Depth of Binary Tree(DFS)
- DFS: 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 31: Minimum Depth of Binary Tree
- [LeetCode] Minimum Depth of Binary Tree - BFS
- 【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
- Linux HugePages 配置 与 Oracle 性能关系说明
- [LeetCode] Flatten Binary Tree to Linked List
- [LeetCode] Path Sum
- [LeetCode] Path Sum II
- [LeetCode] Minimum Depth of Binary Tree - BFS
- [LeetCode] Minimum Depth of Binary Tree - DFS
- [LeetCode] Balanced Binary Tree
- 3DSMax常用快捷键
- [gpu pro]Fast, Stencil-Based Multiresolution Splatting for Indirect Illumination
- 一个非常好的学习SQL的网站 http://ezlearncomputer.com
- 一文讲清楚Windows Mobile和Wince(Windows Embedded CE)的字符集问题
- 43(65)---windows internal 6 mark divd alexa
- 对于解决一些VS 2010/2012 C++ 生成的exe在非编译环境电脑中缺失dll的方法
- Android 如何建立AIDL