leetcode_998. Maximum Binary Tree II
https://leetcode.com/problems/maximum-binary-tree-ii/
在654. Maximum Binary Tree版本的建树基础上,在最后插入一个数。
新节点要么为根节点,原树为其左子树;要么将新节点插在右子树中。
class Solution
{
public:
TreeNode* insertIntoMaxTree(TreeNode* root, int val)
{
if(root == NULL)
{
root = new TreeNode(val);
return root;
}
if(val > root->val)
{
TreeNode* temporary = root;
root = new TreeNode(val);
root->left = temporary;
return root;
}
else
{
root->right = insertIntoMaxTree(root->right, val);
return root;
}
}
};
leetcode_998. Maximum Binary Tree II的更多相关文章
- 【leetcode】998. Maximum Binary Tree II
题目如下: We are given the root node of a maximum tree: a tree where every node has a value greater than ...
- [Swift]LeetCode998. 最大二叉树 II | Maximum Binary Tree II
We are given the root node of a maximum tree: a tree where every node has a value greater than any o ...
- 【LeetCode】998. Maximum Binary Tree II 解题报告(C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 递归 日期 题目地址:https://leetcod ...
- 654. Maximum Binary Tree
654. Maximum Binary Tree 题目大意: 意思就是给你一组数,先选一个最大的作为根,这个数左边的数组作为左子树,右边的数组作为右子树,重复上一步. 读完就知道是递归了. 这个题真尼 ...
- [Leetcode Week14]Maximum Binary Tree
Maximum Binary Tree 题解 原创文章,拒绝转载 题目来源:https://leetcode.com/problems/maximum-binary-tree/description/ ...
- Leetcode之分治法专题-654. 最大二叉树(Maximum Binary Tree)
Leetcode之分治法专题-654. 最大二叉树(Maximum Binary Tree) 给定一个不含重复元素的整数数组.一个以此数组构建的最大二叉树定义如下: 二叉树的根是数组中的最大元素. 左 ...
- LeetCode - 654. Maximum Binary Tree
Given an integer array with no duplicates. A maximum tree building on this array is defined as follo ...
- [Swift]LeetCode654. 最大二叉树 | Maximum Binary Tree
Given an integer array with no duplicates. A maximum tree building on this array is defined as follo ...
- 654. Maximum Binary Tree 最大节点劈开,然后左边、右边排序
[抄题]: Given an integer array with no duplicates. A maximum tree building on this array is defined as ...
随机推荐
- Lightoj 1018 - Brush (IV)
1018 - Brush (IV) PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB Muba ...
- python dig trace 功能实现——通过Querying name server IP来判定是否为dns tunnel
dns tunnel确认方法,查询子域名最终的解析地址: 使用方法:python dig_trace.py "<7cf1e56b 67fc90f8 caaae86e 0787e907 ...
- jQuery入坑指南
前言 Ajax官方文档 爱jQuery jQuery插件库 jQuery中文api input 赋值和取值 记录一下: 在写一个input赋值,二话不说就直接利用了$('#xx').val()来进行取 ...
- form表单提交的几种方法
form表单提交的几种方法 <form id="myform" name="myform" method="post" onsubmi ...
- qr.update导致的java.lang.NullPointerException空指针异常
debug以后代码走到了qr.update这一步,再向下走一步就会报错了,内容是java.lang.NullPointerException 最后再三检查发现是SQL语句写错了!,我写的是插入语句是I ...
- git基本操作(入门)
下面以一个最简单的开发过程,呈现git最基本的操作命令 1.下载代码(以code命名仓库为例) git clone xxxxx/code.git cd code 2.查看所有分支 git branch ...
- jQuery html操作
jQuery 拥有可操作 HTML 元素和属性的强大方法. jQuery DOM 操作 DOM = Document Object Model(文档对象模型) jQuery 中非常重要的部分,就是操作 ...
- Lightoj 1174 - Commandos (bfs)
题目链接: Lightoj 1174 - Commandos 题目描述: 有一军队秉承做就要做到最好的口号,准备去破坏敌人的军营.他们计划要在敌人的每一个军营里都放置一个炸弹.军营里有充足的士兵,每 ...
- _bzoj1051 [HAOI2006]受欢迎的牛【强联通】
传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=1051 保存tarjan模版. 求强联通分量,缩点. #include <cstdio& ...
- 条件DP UVA 672 Gangsters
题目传送门 题意:n个歹徒进饭店,可变化宽度的门,范围[0, k],每个歹徒进门在ti时间进门,身材si,进去后有pi的成功值,问最大的成功值 分析:首先按照进门时间排序,dp[i][j] 表示第i个 ...