Java recursive without global value

  • 0
    public class Solution {
        public TreeNode convertBST(TreeNode root) {
            visit(root, 0);        
            return root;
        int visit(TreeNode root, int greater) {
            if (root == null)
                return greater;
            root.val += helper(root.right, greater);
            return helper(root.left, root.val);

Log in to reply

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