share my java solution


  • 2
    C
    public void flatten(TreeNode root) {
        if(root == null) return;
    
        TreeNode right = root.right;
        root.right = root.left;
        root.left = null;
    
        TreeNode p = root;
        while(p.right != null) p = p.right;
    
        p.right = right;
        flatten(root.right);
    }

Log in to reply
 

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