Maximum Depth of Binary Tree
来源:互联网 发布:unity3d引擎源码 编辑:程序博客网 时间:2024/05/16 12:35
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 binary tree * 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; } int maxLeft = maxDepth(root->left); int maxRig = maxDepth(root->right); return maxLeft > maxRig ? maxLeft + 1 : maxRig + 1; }};
0 0
- Maximum Depth of Binary Tree
- Maximum Depth of Binary Tree
- Maximum Depth of Binary Tree
- Maximum Depth of Binary Tree
- Maximum Depth of Binary Tree
- Maximum Depth of Binary Tree
- Maximum Depth of Binary Tree
- Maximum Depth of Binary Tree
- Maximum Depth of Binary Tree
- Maximum Depth of Binary Tree
- Maximum Depth of Binary Tree
- Maximum Depth of Binary Tree
- Maximum Depth of Binary Tree
- Maximum Depth of Binary Tree
- Maximum Depth of Binary Tree
- Maximum Depth of Binary Tree
- Maximum Depth of Binary Tree
- Maximum Depth of Binary Tree
- LeetCode OJ - Spiral Matrix
- 大处着眼小处着手
- hibernate 动态生成HQL
- Unbunt 12.0.4 安装Mysql
- hibernat异常:Unable to get the default Bean Validation factory
- Maximum Depth of Binary Tree
- asp.net常用页面指令
- Unique Binary Search Trees II
- CF149 E XOR on Segment(线段树成段更新)
- 最近点对问题(分治)
- 主成分分析在nlp中的应用
- Cloudera hadoop-2.3.0-cdh5.1.0 在Centos 6.5 下的安装
- Spring事务配置的五种方式
- 密钥管理 之 数据库取