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 ...
随机推荐
- 洛谷 P2195 HXY造公园
P2195 HXY造公园 题目描述 现在有一个现成的公园,有n个休息点和m条双向边连接两个休息点.众所周知,HXY是一个SXBK的强迫症患者,所以她打算施展魔法来改造公园并即时了解改造情况.她可以进行 ...
- CF #328div2 D
这题不难,当时想出来了,可是却写不出来~~ 现在慢慢写回来,也写得好挫~ 可以知道,被攻击的城市必定可以组成一棵树,然后,传送到的点必定也是城市之一.如果出发后回到原点,则需要2E,E是树的边数,则2 ...
- Libs文件夹下的Jar文件为什么不会自己主动放在Android Private Libraries文件夹下
简而言之:这个问题就是由jar包反复冲突了! 这个问题一開始我出现了一种"自以为是"的答案,在Android Private Libraries文件夹下的是会打包到project可 ...
- MongoDB学习笔记一:MongoDB的下载和安装
MongoDB学习笔记一:MongoDB的下载和安装 趁着这几天比較空暇,准备学习一下MongoDB数据库.今天就简单的学习了一些MongoDB的下载和安装.并创建了存储MongoDB的数据仓库. 将 ...
- leetcode 二分法 Pow(x, n)
Pow(x, n) Total Accepted: 25273 Total Submissions: 97470My Submissions Implement pow(x, n). 题意:求x的n次 ...
- LeetCode OJ 之 Valid Anagram
题目: Given two strings s and t, write a function to determine if t is an anagram of s. For example, s ...
- 关于isset的一点说明
作者:zhanhailiang 日期:2014-10-08 今天遇到一个非常奇怪的bug,測试例如以下: <? php $a = 'abc'; var_dump(isset($a['code'] ...
- 如何将unity资源窗体中的文件一下所有折叠/打开
1.选中父物体 2.按住alt 3.再按下键盘上的左键/右键:此父物体下的所有折叠/打开 或者 alt + LMB 点击所要折叠/打开的父物体左边的小三角
- Android 重写onBackPressed()方法 遇到的问题
1.resultCode的值一直为0 问题描述:AActivity调用startActivityForResult()方法,启动BActivity,然后在BActivity的onBackPressed ...
- Android4.4 wpa_supplicant深入分析之wpa_supplicant初始化流程续
下面我们将接上一篇文章继续分析main中第二个关键函数wpa_supplicant_add_iface. wpa_supplicant_add_iface用于向wpa_supplicant添加接口设备 ...