LeetCodeOJ. Maximum Depth of Binary Tree
见问题: https://oj.leetcode.com/problems/maximum-depth-of-binary-tree/
主题概述
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;
} else {
int leftDepth = maxDepth(root->left) + 1;
int rightDepth = maxDepth(root->right) + 1; return ( leftDepth > rightDepth ? leftDepth : rightDepth );
}
}
};
LeetCodeOJ. Maximum Depth of Binary Tree的更多相关文章
- [LintCode] Maximum Depth of Binary Tree 二叉树的最大深度
Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the long ...
- [Leetcode][JAVA] Minimum Depth of Binary Tree && Balanced Binary Tree && Maximum Depth of Binary Tree
Minimum Depth of Binary Tree Given a binary tree, find its minimum depth. The minimum depth is the n ...
- LeetCode:Minimum Depth of Binary Tree,Maximum Depth of Binary Tree
LeetCode:Minimum Depth of Binary Tree Given a binary tree, find its minimum depth. The minimum depth ...
- LEETCODE —— binary tree [Same Tree] && [Maximum Depth of Binary Tree]
Same Tree Given two binary trees, write a function to check if they are equal or not. Two binary tre ...
- 33. Minimum Depth of Binary Tree && Balanced Binary Tree && Maximum Depth of Binary Tree
Minimum Depth of Binary Tree OJ: https://oj.leetcode.com/problems/minimum-depth-of-binary-tree/ Give ...
- Leetcode | Minimum/Maximum Depth of Binary Tree
Minimum Depth of Binary Tree Given a binary tree, find its minimum depth. The minimum depth is the n ...
- 104. Maximum Depth of Binary Tree(C++)
104. Maximum Depth of Binary Tree Given a binary tree, find its maximum depth. The maximum depth is ...
- 【LeetCode练习题】Maximum Depth of Binary Tree
Maximum Depth of Binary Tree Given a binary tree, find its maximum depth. The maximum depth is the n ...
- leetcode 104 Maximum Depth of Binary Tree二叉树求深度
Maximum Depth of Binary Tree Total Accepted: 63668 Total Submissions: 141121 My Submissions Question ...
随机推荐
- WPF 图片浏览 伪3D效果
原文:WPF 图片浏览 伪3D效果 首先上效果图: 因项目要求,需要把图片以"好看"."炫"的效果展示出来,特地研究了一下WPF关于3D方面的制作,奈何最终成果 ...
- "Cannot find entry symbol nable-stdcll-fixup; defaulting to 00401000" 解决方案
在使用Qt 4.7.3, Qt 4.7.2 ,Qt 4.7.1(mingw 4.6.2 )的时候都会有一个问题无法编译通过,即用Qt Creator 编译的时候会发生一个错误 "Cannot ...
- 【原创】leetCodeOj --- Largest Number 解题报告
原题地址: https://oj.leetcode.com/problems/largest-number/ 题目内容: Given a list of non negative integers, ...
- 【原创】一个基于简单剪枝的DFS解数独程序
问题来源:leetCode Sudoku Solver Write a program to solve aSudoku puzzle by filling the empty cells. Empt ...
- Spring Boot 基础
Spring Boot 基础 Spring Boot 项目(参考1) 提供了一个类似ASP.NET MVC的默认模板一样的标准样板,直接集成了一系列的组件并使用了默认的配置.使用Spring Boot ...
- HDU 1711 Number Sequence(算法验证)
该怎么做.每一个人的人生都应该自己掌握.你给不了别人一切.你也不懂别人的忧伤. 微笑不代表快乐.哭泣不一定悲伤 不努力怎么让关心你的人幸福.不努力怎么让看不起你的人绝望. 我用生命在奋斗--lx_Zz ...
- Android - 支持不同的设备 - 支持不同的平台版本
在最新版本的Android为app提供很好的新API时,也应该继续支持旧版本的Android直到大部分设备已经更新了.这里将要介绍如何在使用最新API带来的优点的同时继续支持老版本. Dashboar ...
- VB高清图标制作方法
我隆重介绍一个软件:ResHacker !!! 这个软件可以修改软件的很多东西包括图标和标题,下面看**作. 运行ResHacker打开要更改图标的exe文件, 图标组--1--右键0--替换资源-- ...
- [TroubleShooting] The server network address can not be reached or does not exist
Backtround: I'm trying to set up mirroring between two sql 2008 R2 databases on different servers in ...
- 顺序表----java实现
最简单的数据结构--顺序表,此处以数组为例. 顺序表的优点:支持随机读取,内存空间利用率高. 顺序表的缺点:1.需要预先给出最大数据元素个数,这往往很难实现. 2.插入和删除时需要移动大量数据. Se ...