/**
* Definition for a binary tree node.
* function TreeNode(val) {
* this.val = val;
* this.left = this.right = null;
* }
*/
/**
* @param {TreeNode} root
* @return {TreeNode}
*/
const convertBST = function (root) {
const value = { sum: 0 }
inorderTraversal(root, value);
return root;
};
const inorderTraversal = function (root, value) {
if (root === null) {
return;
}
inorderTraversal(root.right);
sum += root.val;
root.val = sum;
inorderTraversal(root.left);
};