632. Binary Tree Maximum Node【Naive】
Find the maximum node in a binary tree, return the node.
Given a binary tree:
1
/ \
-5 2
/ \ / \
0 3 -4 -5
return the node with value 3
.
解法一:
class Solution {
public:
/**
* @param root the root of binary tree
* @return the max node
*/
TreeNode* maxNode(TreeNode* root) {
// Write your code here
if (root == NULL) {
return root;
} TreeNode* left = maxNode(root->left);
TreeNode* right = maxNode(root->right); return max(root, max(left, right));
} TreeNode* max(TreeNode* a, TreeNode* b) {
if (a == NULL || b == NULL) {
return (a == NULL ? b : a);
} return (a->val > b->val ? a : b);
} };
632. Binary Tree Maximum Node【Naive】的更多相关文章
- Binary Tree Maximum Node
Find the maximum node in a binary tree, return the node. Example Given a binary tree: 1 / \ -5 2 / \ ...
- 【leetcode】Binary Tree Maximum Path Sum
Binary Tree Maximum Path Sum Given a binary tree, find the maximum path sum. The path may start and ...
- 【LeetCode】124. Binary Tree Maximum Path Sum
Binary Tree Maximum Path Sum Given a binary tree, find the maximum path sum. The path may start and ...
- [leetcode]Binary Tree Maximum Path Sum
Binary Tree Maximum Path Sum Given a binary tree, find the maximum path sum. The path may start and ...
- 26. Binary Tree Maximum Path Sum
Binary Tree Maximum Path Sum Given a binary tree, find the maximum path sum. The path may start and ...
- leetcode 124. Binary Tree Maximum Path Sum 、543. Diameter of Binary Tree(直径)
124. Binary Tree Maximum Path Sum https://www.cnblogs.com/grandyang/p/4280120.html 如果你要计算加上当前节点的最大pa ...
- LeetCode: Binary Tree Maximum Path Sum 解题报告
Binary Tree Maximum Path SumGiven a binary tree, find the maximum path sum. The path may start and e ...
- 二叉树系列 - 二叉树里的最长路径 例 [LeetCode] Binary Tree Maximum Path Sum
题目: Binary Tree Maximum Path Sum Given a binary tree, find the maximum path sum. The path may start ...
- 53. Maximum Subarray【leetcode】
53. Maximum Subarray[leetcode] Find the contiguous subarray within an array (containing at least one ...
随机推荐
- ubuntu 设置静态IP GW
网卡配置静态IP地址 编辑文件/etc/network/interfaces: sudo vi /etc/network/interfaces 并用下面的行来替换有关eth0的行:# The prim ...
- django 基础知识回顾
内容回顾: 1. ajax参数 url: type: data: 1.value不能是字典 {k1:'v1',k2:[1,2,3,],k3; JSON.string} 2.$('').serilize ...
- Echarts的legend改变图例图标为自定义图片
当折线图时,legend默认时rect形式,如果需要改图例形状,可以自己设置legend的icon属性 legend: { icon:'stack' }, 1.自定义每个图例样式:为data的每个对象 ...
- IE浏览器实现复制数据到剪贴板
IE浏览器实现复制数据到剪贴板非常简单,代码如下: if (window.clipboardData) { window.clipboardData.clearData(); window.clipb ...
- 给出a的定义 -- 指针 和 数组
- 搜索引擎爬虫蜘蛛的useragent
百度爬虫 * Baiduspider+(+http://www.baidu.com/search/spider.htm”) google爬虫 * Mozilla/5.0 (compatib ...
- 安装Was liberty之步骤
安装文件下载:http://pan.baidu.com/s/1dDl8PuL 安装三大步骤:拷贝文件,安装VNC和安装WasLiberty 拷贝文件是将需要的文件InstalMgr1.6.2_LNX_ ...
- Sqlserver获取行号
Sqlserver获取行号 select row_number()over(order by userid )as RowNum,*from OUM_User
- 关于UbuntuMate的两个问题点:SSH问题处理与自启动项配置
一.SSH连接报错问题 ssh到某台机器时候,存在如下报错: /usr/bin/xauth: timeout in locking authority file /home/sam/.Xauthori ...
- Flutter混合工程改造实践
背景 6月下旬,我们首次尝试用Flutter开发AI拍app.开发的调研准备阶段没有参考业界实践,导致我们踩到一些填不上的坑.在这些坑中,最让我感到棘手的是Flutter和原生页面混合栈管理的问题. ...