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 ...
随机推荐
- solr入门之多线程操作solr中索引字段的解决
涉及的问题: 建索引时有一个字段是该词语出现的次数,这个字段是放在solr里的 而我用的是多线程来进行全量导入的,这里就涉及到了多线程问题 多个线程操作同一个变量时怎样处理? 我是这样子做的 : 首 ...
- 如何写好react组件
react 组件方面: 总结 React 组件的三种写法 及最佳实践 [涨经验] React组件编写思路(一) 使用react-router实现单页面应用时设置页面间过渡的两种方式 [翻译]基于 Cr ...
- java中字节数组byte[]和字符(字符串)之间的转换
转自:http://blog.csdn.net/linlzk/article/details/6566124 Java与其他语言编写的程序进行tcp/ip socket通讯时,通讯内容一般都转换成by ...
- STM32:获取复位源,软件复位
RCC CSR寄存器会存储复位标示,可通过它来知道复位原因,来源: if(RCC_GetFlagStatus(RCC_FLAG_PINRST)) printf("PINRST\r\n&quo ...
- 2-11 tensorflow常量变量定义
D:\Users\ZHONGZHENHUA\Anaconda3\envs\tensorflow\Lib\site-packages\tensorflow https://developer.nvidi ...
- MySQL基础操作——转
原文: [培训]MySQL yum安装mysql:yum -y install mysql*- 或者 yum -y install mysql* 启动数据库服务:/etc/init.d/mysqld ...
- Thinkpad x230i安装Ubuntu10.04发生no network devices available
这个是由于10.04版本没有集成x230i的网卡驱动导致,需要到http://sourceforge.net/projects/e1000/f ... %20stable/下载最新版本驱动,并安装,之 ...
- python 高阶函数二 map()和reduce()
一.map()函数 map()函数接收两个参数,一个是函数,一个是Iterable,map将传入的函数依次作用到序列的每个元素,并把结果作为新的Iterator返回. >>> fro ...
- bzoj 2208: [Jsoi2010]连通数【tarjan+拓扑+dp】
我总觉得枚举点bfs也行-- tarjan缩点,记一下每个scc的size,bitset压一下scc里的点,然后按拓扑倒序向上合并到达状态,然后加ans的时候记得乘size #include<i ...
- phpstorm最新破解办法(2016-10-30)
还是选择license server.然后复制http://jetbrains.tencent.click/ 这个地址进去就可以啦.不行的时候欢迎留言告知,更新破解方法