Help me find errors: why my code doesn't work?


  • 0
    T

    public TreeNode convertBST(TreeNode root) {
    TreeNode previous=new TreeNode(0);
    transform(root,previous);
    return root;
    }
    public void transform(TreeNode root,TreeNode previous){
    if(root==null) return;
    transform(root.right,previous);
    root.val+=previous.val;
    previous=root;
    transform(root.left,previous);
    }


Log in to reply
 

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