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 ...
随机推荐
- 不常见使用的css
flex和white-space等属性 1.flex属性让所有弹性盒模型对象的子元素都有相同的长度,忽略它们内部的内容.style={{flex:5}},该元素占父元素的六分之五. 2. white- ...
- bzoj5333: [Sdoi2018]荣誉称号
请不要去改题目给的输入,不然你会wa穿... 这么故弄玄虚的题目,肯定要先转换问题 看到这个不断的除2想起别人家的线段树的写法...x的两个孩子是x<<1和x<<1|1 然后问 ...
- 【POJ 2152】 Fire
[题目链接] 点击打开链接 [算法] 同样是树形DP,但是比较难,笔者做这题看了题解 令f[i][j]表示在以i为根的子树中 1.在以i为根的子树中建一些消防站 2.在节点j必须建一个消防站 3.以i ...
- 【转】Vuex 学习总结
对于很多新手来说,只是阅读文档是不好消化,我的建议是看看 vuex 的实例,通过研究实例来学习vuex.这样就会好理解多了.如果还是不能理解,最好办法就是先把store 的四个属性:state, ge ...
- AutoIT: 对文件系统的菜单进行操作,有专门的语句WinMenuSelectItem
对文件系统的菜单进行操作,有专门的语句WinMenuSelectItem: Run("notepad.exe") WinWaitActive("[CLASS:Notepa ...
- iOS开发,#define的使用
1.判断当前设备是不是iOS7以上版本 #define IOS_VERSION_7_OR_ABOVE (([[[UIDevice currentDevice] systemVersion] float ...
- unity3d中对像之间的相互作用的实现
首先这里的对像是面向对像中的对像: 其实就是C#中对像间相互作用的实现: 一.一般面向对像中关联和依赖的方式: 如关联方式: class A{ B m_B; A(B b){ m_B = b; } ac ...
- E20180305-hm-xa
raw adj. 生的,未加工的; 无经验的; 新近完成的; 发炎的,疼痛的; payload n. 有效载荷; (航天器.卫星的) 装备; (车辆等的) 装载货物; (炸弹.导弹的) 爆炸力;
- bzoj 2423: [HAOI2010]最长公共子序列【dp+计数】
设f[i][j]为a序列前i个字符和b序列前j个字符的最长公共子序列,转移很好说就是f[i][j]=max(f[i-1][j],f[i][j-1],f[i-1][j-1]+(a[i]==b[j])) ...
- C# 读写text 详细讲解
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> & ...