Clean Java Recursive Solution


  • 0
    H
    class Solution {
        public TreeNode convertBST(TreeNode root) {
            helper(root, 0);
            return root;
        }
        private int helper(TreeNode node, int sum) {
            if (node == null) return sum;
            node.val += helper(node.right, sum);
            return helper(node.left, node.val);
        }
    }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.