LeetCode Algorithms #104 <Maximum Depth of Binary Tree>
来源:互联网 发布:php 房源管理系统 编辑:程序博客网 时间:2024/05/24 02:20
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.
思路:
简单的递归应用。
解:
/** * 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 maxDepth(TreeNode* root) { if(root == NULL) { return 0; } return 1 + max(maxDepth(root->left), maxDepth(root->right)); }};
0 0
- LeetCode Algorithms #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: 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
- 循环队列实现
- Android基础——Fragment控制切换(一)
- Android基础之Fragment与Activity交互详解(二)
- LeetCode Algorithms #290 <Word Pattern>
- Android基础之使用Fragment控制切换多个页面(三)
- LeetCode Algorithms #104 <Maximum Depth of Binary Tree>
- *LeetCode-Interleaving String
- File类的基本知识
- LeetCode Algorithms #237<Delete Node in a Linked List>
- hdu5499 SDOI
- 【bzoj2226】【spoj5971】【lcmsum】【数论】
- Android 对话框(Dialog)大全 建立你自己的对话框
- 毕业5年决定人的一生(转)-- 大家千万不要错过这篇文章
- Lua入门