LeetCode OJ-- Maximum Depth of Binary Tree
https://oj.leetcode.com/problems/maximum-depth-of-binary-tree/
求二叉树的最大深度
深度优先搜索
/**
* 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 ; int ans = ;
int now_depth;
deep(root,ans,);
return ans;
} void deep(TreeNode *root, int &max_depth, int now_depth)
{
if(root->left == NULL && root->right == NULL)
max_depth = max_depth < now_depth ? now_depth : max_depth; now_depth++; if(root->left)
deep(root->left,max_depth,now_depth);
if(root->right)
deep(root->right,max_depth,now_depth);
}
};
LeetCode OJ-- 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 OJ Minimum Depth of Binary Tree 递归求解
题目URL:https://leetcode.com/problems/minimum-depth-of-binary-tree/ 111. Minimum Depth of Binary T ...
- 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 ...
随机推荐
- 常见的js算法面试题收集,es6实现
1.js 统计一个字符串出现频率最高的字母/数字 let str = 'asdfghjklaqwertyuiopiaia'; const strChar = str => { let strin ...
- BFS:CF356C-Compartments
C. Compartments time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...
- open()函数之文件操作
#open() 文件操作 #打开文件的模式有: r,只读模式[默认] w,只写模式[不可读:不存在则创建:存在则清空内容:] x,只写模式[不可读:不存在则创建,存在则报错] a,追加模式[可读:不存 ...
- 第5模块闯关CSS练习题
1.列举你知道的css选择器? 说道css选择器,大家都知道有许多种,但是真要你去掰着手指头数一数的话,你可能需要数几分钟.其实这么多选择器,完全可以分为两类: 标签选择器(*是特殊情况),可但标签, ...
- TCP/IP网络编程之网络编程和套接字
网络编程和套接字 网络编程又称为套接字编程,就是编写一段程序,使得两台连网的计算机彼此之间可以交换数据.那么,这两台计算机用什么传输数据呢?首先,需要物理连接,将一台台独立的计算机通过物理线路连接在一 ...
- MySQL基础3-SQL语言
1.DQL语句分类 重点在于Select语句 2.Sql语句的书写规则 3.怎样使用Navicat导入已经写好的sql文件 (1)在Navicat中右击选中的数据库 (2)将sql文件所在的路径添加进 ...
- python 令人抓狂的编码问题
#运行以下程序: #! /usr/bin/env python#coding=utf-8 file = open( 'all_hanzi.txt','wb' ) listhz = []n=0for c ...
- TopK-微博今日热门话题
大纲 TopK on single node TopK on multiple nodes Realtime topK with low QPS Realtime topK with high QPS ...
- Leetcode 507.完美数
完美数 对于一个 正整数,如果它和除了它自身以外的所有正因子之和相等,我们称它为"完美数". 给定一个 正整数 n, 如果他是完美数,返回 True,否则返回 False 示例: ...
- js日期处理
Js获取当前日期时间及其它操作 var myDate = new Date(); myDate.getYear(); //获取当前年份(2位) myDate.getFullYear(); //获取完整 ...