Java Concise Inorder


  • 0
    public class Solution {
        private int sum = 0;
        public TreeNode convertBST(TreeNode root) {
            if (root == null) return root;
            dfs(root);
            return root;
        }
        private void dfs(TreeNode root) {
            if (root == null) return;
            dfs(root.right);
            root.val += sum;
            sum = root.val;
            dfs(root.left);
        }
    }
    

Log in to reply
 

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