@@ -0,0 +1,1120 @@
+/***%0A * Given a binary tree where all the right nodes are either leaf nodes with %0A * a sibling (a left node that shares the same parent node) or empty, %0A * %0A * Flip it upside down and turn it into a tree where the original right nodes turned into left leaf nodes. %0A * Return the new root.%0A * %0A * For example:%0A * Given a binary tree %7B1,2,3,4,5%7D,%0A *     1%0A *    / %5C%0A *   2   3%0A *  / %5C%0A * 4   5%0A * return the root of the binary tree %5B4,5,2,#,#,3,1%5D.%0A *    4%0A *   / %5C%0A *  5   2%0A *     / %5C%0A *    3   1  %0A */%0A/**%0A * Definition for binary tree%0A * public class TreeNode %7B%0A *     int val;%0A *     TreeNode left;%0A *     TreeNode right;%0A *     TreeNode(int x) %7B this.val = x; this.left = null;this.right = null;%7D%0A * %7D;%0A */%0A%0Apublic class Solution %7B%0A     public TreeNode UpsideDownBinaryTree(TreeNode root) %7B%0A         TreeNode cur = root, parent = null, pright = null;%0A         while (cur != null) %7B%0A             TreeNode left = cur.left;%0A             cur.left = pright;%0A             pright = cur.right;%0A             cur.right = parent;%0A             parent = cur;%0A             cur = left;%0A         %7D%0A         return parent;%0A     %7D%0A%7D%0A%0A

add BinaryTreeUpsideDown.java