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 ...
随机推荐
- 解决cmd目录下pip命令不存在的问题
解决cmd目录下pip命令不存在的问题 注:pip.exe程序在Python安装目录下的scripts中1.在cmd命令中输入: 先输入:python -m ensurepip 再输入:python ...
- ubuntu 把软件源修改为国内源和更新(转载)
1. 备份原始文件 sudo cp /etc/apt/sources.list /etc/apt/sources.list.backup 2. 修改文件并添加国内源 vi /etc/apt/sourc ...
- A * B Problem Plus HDU - 1402 (FFT)
A * B Problem Plus HDU - 1402 (FFT) Calculate A * B. InputEach line will contain two integers A and ...
- poj 3259 时光穿梭问题 bellman_ford算法
题意:有n个空地,有m条双向大路,w条时光隧道单向路.问能否回到过去? 思路:判断是否有负环存在,如果有负环存在那么就可以一直小就可以回到过去了 创建源顶点 V到其他顶点的距离d 初始为INF d[1 ...
- 笔记-http-header
笔记-http-header 1. Requests部分 Host:请求的web服务器域名地址 User-Agent:HTTP客户端运行的浏览器类型的详细信息.通过该头部信息,web服务器可 ...
- Appium环境搭建及“fn must be a function”问题解决
由于appium在线安装比较困难,大多数应该是由于FQ造成的吧,索性直接下载appium安装包:http://pan.baidu.com/s/1bpfrvjD nodejs下载也很缓慢,现提供node ...
- TCP/IP网络编程之多线程服务端的实现(二)
线程存在的问题和临界区 上一章TCP/IP网络编程之多线程服务端的实现(一)的thread4.c中,我们发现多线程对同一变量进行加减,最后的结果居然不是我们预料之内的.其实,如果多执行几次程序,会发现 ...
- Notepad++ 32 位 PluginManager 下载
github 下载地址:(有 64 位的哦) https://github.com/bruderstein/nppPluginManager/releases 1. PluginManager 管理插 ...
- 【BZOJ 3620】似乎在梦中见过的样子
题目 (夢の中で逢った.ような--) 「Madoka,不要相信 QB!」伴随着 Homura 的失望地喊叫,Madoka 与 QB 签订了契约. 这是 Modoka 的一个噩梦,也同时是上个轮回中所发 ...
- Windows下Eclipse安装PyDev
事后证明PyDev不好用,推荐使用pycharm!!! 1.安装eclipse,这个网上一大堆,就不说了 2.安装python,这个网上一大堆,就不说了 3.Eclipse安装PyDev 第一种在 ...