Binary Search Tree to Greater Sum Tree LeetCode solution in Python

1
# Runtime: 36 ms (Top 83.6%) | Memory: 16.39 MB (Top 54.5%)
2

3

4
class Solution:
5
def bstToGst(self, root):
6
self.total = 0
7

8
def dfs(n):
9
if n:
10
dfs(n.right)
11
self.total += n.val
12
n.val = self.total
13
dfs(n.left)
14

15
dfs(root)
16
return root

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0