-
Notifications
You must be signed in to change notification settings - Fork 160
/
binary-search-tree-to-greater-sum-tree.md
38 lines (28 loc) · 1.47 KB
/
binary-search-tree-to-greater-sum-tree.md
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<p>Given the root of a binary <strong>search</strong> tree with distinct values, modify it so that every <code>node</code> has a new value equal to the sum of the values of the original tree that are greater than or equal to <code>node.val</code>.</p>
<p>As a reminder, a <em>binary search tree</em> is a tree that satisfies these constraints:</p>
<ul>
<li>The left subtree of a node contains only nodes with keys <strong>less than</strong> the node's key.</li>
<li>The right subtree of a node contains only nodes with keys <strong>greater than</strong> the node's key.</li>
<li>Both the left and right subtrees must also be binary search trees.</li>
</ul>
<p> </p>
<p><strong>Example 1:</strong></p>
<p><strong><img alt="" src="https://assets.leetcode.com/uploads/2019/05/02/tree.png" style="width: 280px; height: 191px;" /></strong></p>
<pre>
<strong>Input: </strong><span id="example-input-1-1">[4,1,6,0,2,5,7,null,null,null,3,null,null,null,8]</span>
<strong>Output: </strong><span id="example-output-1">[30,36,21,36,35,26,15,null,null,null,33,null,null,null,8]</span>
</pre>
<div>
<p> </p>
</div>
<p><strong>Note:</strong></p>
<ol>
<li>The number of nodes in the tree is between <code>1</code> and <code>100</code>.</li>
<li>Each node will have value between <code>0</code> and <code>100</code>.</li>
<li>The given tree is a binary search tree.</li>
</ol>
<div>
<div>
<div> </div>
</div>
</div>