12345678910111213141516171819202122232425 |
- var sum int = 0
- /**
- * Definition for a binary tree node.
- * type TreeNode struct {
- * Val int
- * Left *TreeNode
- * Right *TreeNode
- * }
- */
- func convertBST(root *TreeNode) *TreeNode {
- sum = 0
- inorder(root)
- return root
- }
- func inorder(root *TreeNode) {
- if root == nil {
- return
- }
- inorder(root.Right)
- root.Val += sum
- sum = root.Val
- inorder(root.Left)
- }
|