[leetcode刷题系列]Maximum Depth of Binary Tree
来源:互联网 发布:mac 免费uml建模工具 编辑:程序博客网 时间:2024/05/28 03:03
囧, 继续模拟, 继续指针!
/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */class Solution { void dfs(TreeNode * root, int now, int & ans){ ans = max(ans, now); if(root->left != 0) dfs(root->left, now + 1, ans); if(root->right != 0) dfs(root->right, now + 1, ans); }public: int maxDepth(TreeNode *root) { // Start typing your C/C++ solution below // DO NOT write int main() function if(root == 0) return 0; int ans = 0; dfs(root, 1, ans); return ans; }};
- [leetcode刷题系列]Maximum Depth of Binary Tree
- LeetCode刷题笔录 Maximum Depth of Binary Tree
- Leetcode - Tree - Maximum Depth of Binary Tree
- [leetcode][tree] Maximum Depth of Binary Tree
- LeetCode Maximum Depth of Binary Tree
- [Leetcode] Maximum Depth of Binary Tree
- leetcode 24: Maximum Depth of Binary Tree
- [LeetCode] Maximum Depth of Binary Tree
- Leetcode 104 Maximum Depth of Binary Tree
- 【leetcode】Maximum Depth of Binary Tree
- [leetcode]Maximum Depth of Binary Tree
- [LeetCode]Maximum Depth of Binary Tree
- [leetcode]Maximum Depth of Binary Tree
- Leetcode: Maximum Depth of Binary Tree
- LeetCode-Maximum Depth of Binary Tree
- [leetcode] Maximum Depth of Binary Tree
- LeetCode - Maximum Depth of Binary Tree
- LeetCode:Maximum Depth of Binary Tree
- 设置指定文字的颜色
- nyoj 62 笨小熊
- 01-http消息头剖析-http协议
- 02-打印http消息头详细的信息
- PAT练习题概览
- [leetcode刷题系列]Maximum Depth of Binary Tree
- 【cocos2D-x学习】9.音乐炫台——音效与特效
- 看截图:给图片罩上一层半透明文字描述效果(一)DIV+CSS+SPAN 借鉴百度图片附着文字效果
- NYOJ 85题 有趣的数
- Struts2常用标签总结
- hdu 1673 Optimal Parking
- 03-打印访问者的IP地址
- [leetcode刷题系列]Minimum Depth of Binary Tree
- Oracle 11g启动服务,账户被锁定等问题的解决