Convert BST to Greater Tree – LeetCode 538
Problem
Description
Given a Binary Search Tree (BST), convert it to a Greater Tree such that every key of the original BST is changed to the original key plus sum of all keys greater than the original key in BST.
Answer
Original
Code
1 | /** |
思路
逆向的中序便利累加。时间复杂度$O(n)$,空间复杂度$O(log(n))$。
耗时$24$ ms,排名$2.48\%$
Better
思路
还没看到更好的思路。