JAVA - Process Right Trees First - Beats 95% - 5 lines!


  • 0
    J
    public class Solution {
        public TreeNode convertBST(TreeNode root) {
            recur(root, 0);
            return root;
        }
        
        public int recur(TreeNode current, int parent) {
            if(current == null) return 0;
            current.val += recur(current.right, parent) + parent;
            return current.val - parent + recur(current.left, current.val);
        }
    }
    

Log in to reply
 

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