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 ...
随机推荐
- XMU 1056 瞌睡 vs 听课 【动态规划】
1056: 瞌睡 vs 听课 Time Limit: 500 MS Memory Limit: 64 MBSubmit: 19 Solved: 6[Submit][Status][Web Boar ...
- intellij IDEA破解
方法1 填入下面的license server: http://intellij.mandroid.cn/ http://idea.imsxm.com/ http://idea.iteblog.com ...
- YTU 2903: A--A Repeating Characters
2903: A--A Repeating Characters 时间限制: 1 Sec 内存限制: 128 MB 提交: 50 解决: 30 题目描述 For this problem,you w ...
- webstorm使用帮助(转自http://my.oschina.net/longteng2013/blog/138010),另外有部分内容摘自其它人博客
为了更高效的开发代码,这里列出了一些webstorm的快捷键和zencoding 发表于1 年 前(2013-06-17 00:19) 阅读(2101) | 评论(2) 11人收藏此文章, 我要收 ...
- 比特币客户端bitcoind的高级用法
Bitcoin 比特币官方客户端有两个版本:一个是图形界面的版本,通常被称为 Bitcoin(首字母大写),以及一个简洁命令行的版本(称为 bitcoind).它们相互间是兼容的,有着同样的命令行参数 ...
- javascript 省、市、地县三级联动
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><HTML><HEAD&g ...
- java web框架收集
一.前端框架: 1.vue.js 2.angular.js 二.后端框架: 1.struts2 2.springmwc 三.数据库映射框架: 1.hibernate 2.mybatis 四.数据库: ...
- linux修改用户主目录的方法 (转载)
转自:http://xiaomaimai.blog.51cto.com/1182965/274002 第一:修改/etc/passwd文件第二:usermod命令 详细说明如下:第一种方法:vi /e ...
- HDU1072:Nightmare [DFS]
题目链接:Nightmare 题意: 给出一张n*m的图,0代表墙,1代表可以走,2代表起始点,3代表终点,4代表炸弹重置点 问是否能从起点到达终点 分析: 一道很好的DFS题目,炸弹重置点必然最多走 ...
- mysql查询流程
首先是连接器 连接器负责跟客户端来链接 链接成功后 mysql会先去查询缓存,之前是不是有查询的这条语句,之前执行过的话 就会以key-value的形式缓存到内存中,如果没有就会继续执行后面的,执行完 ...