My 10-line Java recursive solution

  • 0


    public class Solution {
        public TreeNode convertBST(TreeNode root) {
            if (root == null) return null;
            convertBST(root, 0);
            return root;
        private int convertBST(TreeNode root, int currSum) {
            if (root == null) return currSum;
            root.val += convertBST(root.right, currSum);
            return convertBST(root.left, root.val);


Log in to reply

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