Java only one extra variable easy reverse inorder solution


  • 0
    S
    public class Solution {
        int total = 0;
        public TreeNode convertBST(TreeNode root) {
            if(root == null){
                return null;
            }
            convertBST(root.right);
            root.val = root.val + total;
            total = root.val;
            convertBST(root.left);
            return root;
        }
    }
    

Log in to reply
 

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