# leetcode538.把二叉树转化成累加树

```golang
/**
 * Definition for a binary tree node.
 * type TreeNode struct {
 *     Val int
 *     Left *TreeNode
 *     Right *TreeNode
 * }
 */
 var res int
func convertBST(root *TreeNode) *TreeNode {
    res=0
    dfs(root)
    return root
}

func dfs(root *TreeNode){
    if root==nil{
        return
    }
    dfs(root.Right)
    res=res+root.Val    
    root.Val=res
    dfs(root.Left)
}
```
