【LeetCode】Maximum Depth of Binary Tree
http://oj.leetcode.com/problems/maximum-depth-of-binary-tree/

public class Solution {
public int maxDepth(TreeNode root) {
if(root!=null){
int depth=0;
InOrder(root,depth);
}
return max;
}
public int max=0;
private void InOrder(TreeNode root, int depth) {
if(root!=null){
depth++;
if(max<depth){
max=depth;
}
InOrder(root.left,depth);
InOrder(root.right,depth);
depth--;
}
}
}
【LeetCode】Maximum Depth of Binary Tree的更多相关文章
- 【LeetCode】Maximum Depth of Binary Tree(二叉树的最大深度)
这道题是LeetCode里的第104道题. 给出题目: 给定一个二叉树,找出其最大深度. 二叉树的深度为根节点到最远叶子节点的最长路径上的节点数. 说明: 叶子节点是指没有子节点的节点. 示例: 给定 ...
- 【LeetCode】Minimum Depth of Binary Tree 二叉树的最小深度 java
[LeetCode]Minimum Depth of Binary Tree Given a binary tree, find its minimum depth. The minimum dept ...
- 【Leetcode】【Easy】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】Minimum Depth of Binary Tree
题目简述: Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along th ...
- 【leetcode】Minimum Depth of Binary Tree (easy)
Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shor ...
- 【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 | 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 ...
随机推荐
- Word Ladder系列
1.Word Ladder 问题描述: 给两个word(beginWord和endWord)和一个字典word list,找出从beginWord到endWord之间的长度最长的一个序列,条件: 1. ...
- Yii关联查询(转载)
原文链接:http://keshion.iteye.com/blog/1607994 一.多表关联的配置 在我们使用 AR 执行关联查询之前,我们需要让 AR 知道一个 AR 类是怎样关联到另一个的. ...
- php解析json字符串变量总是空白null
通过接口获取的json字符串使用json_decode始终无法正确解析,返回空白. 直接把结果字符串复制出来手动创建一个变量却正常,在前端js也能解析,搞了半天不得其解,最后发现是接口输出的结果包含有 ...
- 深入了解Entity Framework框架及访问数据的几种方式
一.前言 1.Entity Framework概要 Entity Framework是微软以ADO.NET为基础所发展出来的对象关系映射(O/R Mapping)解决方案.该框架曾经为.NET Fra ...
- js - 锚点-scrollIntoView()
document.getElementById("view").scrollIntoView(false);
- js 路径改变时获取url参数
当我们在使用react或vue的router作路由跳转时,为了保持菜单与地址栏状态一致,我们可以使用window.onhashchange捕获#后面的变化 window.onhashchange = ...
- 计蒜客 微软大楼设计方案(RMQ)
题目链接 微软大楼设计方案 中文题就不说题意了~ 首先是简单版本 满足$1 <= n, m <= 50$ 那么设$c[i][j]$为从第$i$幢楼到第$j$幢楼的最低的那幢楼的高度 计算两 ...
- 洛谷——P2919 [USACO08NOV]守护农场Guarding the Farm
P2919 [USACO08NOV]守护农场Guarding the Farm 题目描述 The farm has many hills upon which Farmer John would li ...
- ML | spectral clustering
What's xxx In multivariate statistics and the clustering of data, spectral clustering techniques mak ...
- 信号板拼包:数组方式(bug长度只是截短,并未清空,若之后拷贝数据长度小于之前数据长度,老数据会接在后面)
class SignalobardMsgReadHandler : public SessionVectChar::ReadHandler{public: SignalobardMsgReadHan ...