LeetCode -- 1038. Binary Search Tree to Greater Sum Tree
/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */ class Solution { public: int preroot = 0; TreeNode* bstToGst(TreeNode* root) { if(root->right) bstToGst(root->right); preroot = root->val = root->val + preroot; if(root->left) bstToGst(root->left); return root; } };
LeetCode -- 1038. Binary Search Tree to Greater Sum Tree的更多相关文章
- 【leetcode】1038. Binary Search Tree to Greater Sum Tree
题目如下: Given the root of a binary search tree with distinct values, modify it so that every node has ...
- LeetCode: Validata Binary Search Tree
LeetCode: Validata Binary Search Tree Given a binary tree, determine if it is a valid binary search ...
- LeetCode:Unique Binary Search Trees I II
LeetCode:Unique Binary Search Trees Given n, how many structurally unique BST's (binary search trees ...
- Transform a BST to greater sum tree
Given a BST, transform it into greater sum tree where each node contains sum of all nodes greater th ...
- [LeetCode] Validate Binary Search Tree 验证二叉搜索树
Given a binary tree, determine if it is a valid binary search tree (BST). Assume a BST is defined as ...
- [LeetCode] Closest Binary Search Tree Value II 最近的二分搜索树的值之二
Given a non-empty binary search tree and a target value, find k values in the BST that are closest t ...
- [LeetCode] Closest Binary Search Tree Value 最近的二分搜索树的值
Given a non-empty binary search tree and a target value, find the value in the BST that is closest t ...
- [LeetCode] Recover Binary Search Tree 复原二叉搜索树
Two elements of a binary search tree (BST) are swapped by mistake. Recover the tree without changing ...
- [LeetCode] Validate Binary Search Tree (两种解法)
Given a binary tree, determine if it is a valid binary search tree (BST). Assume a BST is defined as ...
随机推荐
- Clojure:日期操作方法
;; 日期格式转换 (def df (java.text.SimpleDateFormat. "yyyy-MM-dd hh:mm:ss")) ;; 字符串转换到日期 (defn s ...
- HDU 5433
每次BC都好心酸... BFS+queue..状态可以设为p_val[x][y][k],加上斗志的值. #include <iostream> #include <cstdio> ...
- C语言编程入门——程序练习(上)
大家能够敲写一下以下的练习代码.看下执行结果,都非常easy.关键要理解. if: # include <stdio.h> int main(void) { int i = 1; i = ...
- ASP.NET MVC脚本及样式压缩
现在我用ASP.NET MVC4.0,发现它自带有脚本和样式压缩功能.不知道以前的版本有木有,没有深究.太棒了!以前我们还辛辛苦苦自己搞了一个压缩的东西.这再次说明,平庸程序员如我辈,应该把时间和精力 ...
- luogu2828 [HEOI2016/TJOI2016]排序
题目大意 给出一个1到n的全排列,现在对这个全排列序列进行m次局部排序,排序分为两种:(0,l,r)表示将区间[l,r]的数字升序排序:(1,l,r)表示将区间[l,r]的数字降序排序.最后询问第q位 ...
- SuperSocketClientEngine
https://github.com/kerryjiang/SuperSocket.ClientEngine TcpClientSession的用法 https://github.com/kerryj ...
- web动画小结
前端写动画,无非两种方案,一种是通过css,另一种是js css的方案: 1.transform的单独使用 (IE9+) rotate(90deg) 2d旋转,也可以理解为沿着3D的Z轴旋转 rota ...
- php 图片生成器
一.需求 最近公司由于有大量的海报要做,而且海报的布局规模都是一样的,只是内容不同,所以老板想我开发一个图片的生成器.可以根据你输入的内容生成海报图片. 具体有需求有以下的需求 1.可以根据将每条数据 ...
- 在redhat6上装1.8以下的docker
因为目前1.8以上的docker最低要求是3.10的Linux内核,而我的内核版本远低于此. [root@localhost home]# uname -r -.el6.x86_64 鉴于我的vm上有 ...
- C++中const用法
1.const和指针: 如果const出现在星号左边,表示被指物是常量:如果出现在星号右边,表示指针自身是常量:如果出现在星号两边,表示被指物和指针两者都是常量. char greet[] = “He ...