Maximum Depth of Binary Tree
来源:互联网 发布:淘宝16年打假 编辑:程序博客网 时间:2024/05/16 07:18
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.
#include<iostream>#include<vector>#include<algorithm>using namespace std;struct TreeNode {int val;TreeNode *left;TreeNode *right;TreeNode(int x) : val(x), left(NULL), right(NULL) {}};int maxDepth(TreeNode *root) {if (root == NULL)return 0;int leftdepth = maxDepth(root->left);int rightdepth = maxDepth(root->right);return max(leftdepth, rightdepth) + 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
- IO流第七课,字符流、纯文本、节点流,Reader、FileReader、Writer、FileWriter读取、写出、拷贝
- 【深入浅出IOS开发】Xcode 6如何创建一个空的Empty Application
- 第四周阅读程序 (4)
- HomeKit 开发指南(中文版)
- 两分钟窃取身边女神微博帐号?详解Android App AllowBackup配置带来的风险
- Maximum Depth of Binary Tree
- USART试wifi模块-emw8266
- 都是做游戏,为嘛国内外出来的产品相差这么大?
- 【深入浅出IOS开发】UIApplication和UIApplicationDelegate详解
- android 重构 1
- 欢迎使用CSDN-markdown编辑器
- 4、数组与方法(二)
- Swift控制转移语句
- 关于IOS 32位与64位介绍