Skip to content

Commit

Permalink
Create 0538-convert-bst-to-greater-tree.kt
Browse files Browse the repository at this point in the history
  • Loading branch information
a93a authored Oct 28, 2023
1 parent 655c2b2 commit 66292aa
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions kotlin/0538-convert-bst-to-greater-tree.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class Solution {
fun convertBST(root: TreeNode?): TreeNode? {
var curSum = 0

fun dfs(node: TreeNode?) {
node?: return

dfs(node.right)
val temp = node.`val`
node.`val` += curSum

curSum += temp
dfs(node.left)
}

dfs(root)
return root
}
}

0 comments on commit 66292aa

Please sign in to comment.