[leetcode] 8. Maximum Depth of Binary Tree
可能是因为我是按难度顺序刷的原因,这个其实在之前的几道题里面已经写过了。题目如下:
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;
else
{
int aspros = maxDepth(root->left);
int defteros = maxDepth(root->right);
return 1 + (aspros>defteros ? aspros : defteros);
}
}
};
非常简单,重复复用。
[leetcode] 8. Maximum Depth of Binary Tree的更多相关文章
- 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 ...
- leetcode 104 Maximum Depth of Binary Tree二叉树求深度
Maximum Depth of Binary Tree Total Accepted: 63668 Total Submissions: 141121 My Submissions Question ...
- LeetCode 104. Maximum Depth of Binary Tree C++ 解题报告
104. Maximum Depth of Binary Tree -- Easy 方法 使用递归 /** * Definition for a binary tree node. * struct ...
- [LeetCode] 104. Maximum Depth of Binary Tree 二叉树的最大深度
Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the long ...
- (二叉树 BFS DFS) leetcode 104. 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 题解]: 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 104. 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 104. Maximum Depth of Binary Tree
Problem: Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along ...
- leetcode 104 Maximum Depth of Binary Tree ----- java
Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the long ...
- Java [Leetcode 104]Maximum Depth of Binary Tree
题目描述: Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along th ...
随机推荐
- emacs之配置8,gdb调试设置
emacsConfig/gdb-setting.el (global-set-key [(f5)] 'gud-go) (global-set-key [(f7)] 'gud-step) (global ...
- ThinkJava-新IO
package com.java.io; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io ...
- java web 程序---javabean实例--登陆界面并显示用户名和密码
重点:注意大小写,不注意细节,这点小事,还需要请教 发现一个问题,也是老师当时写的时候,发现代码没错,但是就是运行问题. 大家看,那个java类,我们要求是所有属性均为私有变量,但是方法为公有的,如果 ...
- nodejs+express+ejs+mongoose实例
nodejs+express+ejs+mongoose实例 nodejs学得异常痛苦,在这里将学的东西做一番整理,算是自我安慰吧.根据网上todo示例,用express和mongoose重写了部分代码 ...
- 用MyEclipse JPA创建项目
http://www.myeclipsecn.com/learningcenter/persistence-development/myeclipse-jpa/ 用MyEclipse JPA创建项目 ...
- Eureka 客户端 配置Eureka 爬坑
配置客户端 eureka.client.register-with-eureka=true eureka.client.fetch-registry=true eureka.client.servic ...
- UNITY Destroy()和DestroyImadiate()的区别
using System.Collections; using System.Collections.Generic; using System.Timers; using UnityEngine; ...
- Symfony 建立一个Bundle
如果说,这个时候你萌生了一个去看一看Symfony源码的想法,个人建议还是算了,看了之后,你就会感到非常迷茫.因为他实在是大于绝大部分你使用过的框架,并且有多达近二十个的插件,使用了一些非常精巧的设计 ...
- node升级更新最近稳定版
今天,又发现一个超级简单的升级Node.js的方法.一行命令搞定,省去了重新编译安装的过程. node有一个模块叫n(这名字可够短的...),是专门用来管理node.js的版本的. 首先安装n模块: ...
- python多线程与线程
进程与线程的概念 进程 考虑一个场景:浏览器,网易云音乐以及notepad++ 三个软件只能顺序执行是怎样一种场景呢?另外,假如有两个程序A和B,程序A在执行到一半的过程中,需要读取大量的数据输入(I ...