Accepted Java Solution w/ Post Order traversal


  • 0
    F

    class Solution {

    public void flatten(TreeNode root) {
        postOrder(root);
    }
    public void postOrder(TreeNode curr) {
        if (curr != null) {
            postOrder(curr.left);
            postOrder(curr.right);
            TreeNode left = curr.left;
            TreeNode right = curr.right;
            if (left != null) {
                curr.right = left;
                curr.left = null;
                while (curr.right != null) {
                    curr = curr.right;
                }
                curr.right = right;
            }
        }
    }
    

    }


Log in to reply
 

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