my java solution


  • 0
    public TreeNode upsideDownBinaryTree(TreeNode root) {
            TreeNode nextLeft = null,nextRight = null,next = root;
            while(next != null) {
                root = next;
                next = root.left;
                root.left = nextLeft;
                nextLeft = root.right;
                root.right = nextRight;
                nextRight = root;
            }
            return root;
        }

Log in to reply
 

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