8.Maximum Depth of Binary Tree
/**
 * 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;
            if(root->left!=NULL&&root->right!=NULL)
                return max(maxDepth(root->left)+1,maxDepth(root->right)+1);
            else if(root->left==NULL&&root->right!=NULL) return maxDepth(root->right)+1;
            else if(root->right==NULL&&root->left!=NULL) return maxDepth(root->left)+1;
            else return 1;
    }
};8.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 ... 
- LeetCode Javascript实现 258. Add Digits 104. Maximum Depth of Binary Tree 226. Invert Binary Tree
		258. Add Digits Digit root 数根问题 /** * @param {number} num * @return {number} */ var addDigits = func ... 
随机推荐
- Spring Cloud Gateway GatewayFilter的使用
			Spring Cloud Gateway GatewayFilter的使用 一.GatewayFilter的作用 二.Spring Cloud Gateway内置的 GatewayFilter 1.A ... 
- ASP的调试技术解答
			一. 调试 ASP.NET 应用程序时出现"未将项目配置为进行调试"的错误信息 症状 当您在 Visual Studio .NET 中调试 ASP.NET 应用程序时,可能会出现下 ... 
- 字符串压缩 牛客网 程序员面试金典 C++ Python
			字符串压缩 牛客网 程序员面试金典 C++ Python 题目描述 利用字符重复出现的次数,编写一个方法,实现基本的字符串压缩功能.比如,字符串"aabcccccaaa"经压缩会变 ... 
- JAVA笔记15__TCP服务端、客户端程序 / ECHO程序 /
			/** * TCP:传输控制协议,采用三方握手的方式,保证准确的连接操作. * UDP:数据报协议,发送数据报,例如:手机短信或者是QQ消息. */ /** * TCP服务器端程序 */ public ... 
- 极速上手 VUE 3—v-model 的使用变化
			本篇文章主要介绍 v-model 在 Vue2 和 Vue3 中使用变化. 一.Vue2 中 v-model 的使用 v-model 是语法糖,本质还是父子组件间的通信.父子组件通信时有两种方式: 父 ... 
- Win10下C语言转8086汇编
			目录 Win10下C语言转8086汇编 简介 开始 写C代码 转换成汇编代码 Win10下C语言转8086汇编 简介 最近学习<王爽汇编>,然后突发奇想,想一边写C语言用编译器将其翻译成汇 ... 
- 记录一次因subprocess PIPE 引起的线上故障
			sence:python中使用subprocess.Popen(cmd, stdout=sys.STDOUT, stderr=sys.STDERR, shell=True) ,stdout, stde ... 
- 『学了就忘』Linux基础命令 — 28、别名和常用快捷键
			目录 1.别名 2.常用快捷键 1.别名 别名也是Shell中的命令. 命令的别名,就是命令的小名,主要是用于照顾管理员使用习惯的. 命令格式: # 查询系统中命令别名 [root@localhost ... 
- cpu内核态与用户态
			1.操作系统需要两种CPU状态 内核态(Kernel Mode):运行操作系统程序,操作硬件 用户态(User Mode):运行用户程序 2.指令划分 特权指令:只能由操作系统使用.用户程序不能使用的 ... 
- Cookie、Session、localStorage、sessionStorage区别和用法
			Cookie 在学习一个新知识点前,我们应该明白自己的学习目标,要带着疑问去学习,该小节须要了解 Cookies 什么是cookie,cookie的作用 cookie的工作机制,即cookie是运作流 ... 
