leetcode 104 Maximum Depth of Binary Tree
来源:互联网 发布:金蝶软件数据恢复 编辑:程序博客网 时间:2024/05/16 17:15
Given a binary tree, find its maximum depth.
The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.
Subscribe to see which companies asked this question
/** * 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 preOrder(TreeNode *root, int hight, int &maxH) {if(root!=NULL) {if(hight>maxH) maxH=hight;preOrder(root->left, hight+1, maxH);preOrder(root->right, hight+1, maxH);}return maxH;} int maxDepth(TreeNode* root) { int maxH = 0; if(root==NULL) return 0;return preOrder(root, 1, maxH); }};
0 0
- Leetcode 104 Maximum Depth of Binary Tree
- LeetCode(104)Maximum Depth of Binary Tree
- LeetCode 104 Maximum Depth of Binary Tree
- LeetCode: Maximum Depth of Binary Tree [104]
- Leetcode(104)Maximum Depth of Binary Tree
- [leetcode 104] Maximum Depth of Binary Tree
- LeetCode 104 Maximum Depth of Binary Tree
- leetCode #104 Maximum Depth of Binary Tree
- LeetCode 104: Maximum Depth of Binary Tree
- LeetCode 104 Maximum Depth of Binary Tree
- leetcode || 104、Maximum Depth of Binary Tree
- LeetCode 104: Maximum Depth of Binary Tree
- leetcode[104]:Maximum Depth of Binary Tree
- Leetcode[104]-Maximum Depth of Binary Tree
- Leetcode---(104)Maximum Depth of Binary Tree
- leetcode-104-Maximum Depth of Binary Tree
- Leetcode #104 Maximum Depth of Binary Tree
- leetcode 104: Maximum Depth of Binary Tree
- 正则表达式--非捕获
- 关于解决使用Ueditor时调用setContent()浏览器会报错问题
- 【搜索那些事】细谈lucene(三)lucene核心API简介
- NHOI2016的解题报告
- iOS开发中常用第三方库的整理
- leetcode 104 Maximum Depth of Binary Tree
- C#—MDI(多文档界面)
- Ubuntu 升级内核
- Project Euler 69
- Lucene教程详解
- iOS中的多线程
- 筛素数法(改进版)
- centos6.5 配置FTP
- SVN 提交错误--执行上下文错误,远程计算机强制关闭一个现有连接