Can you explain what if the tree is like following shape?

1
/ \
2 3
/ / \
4 5 6

I think this tree is qualified with the definition of the problem.

But your solution will return

4
\
2
/ \
3 1
/ \
5 6

while the Node 6 is still a right node.

So my solution is very similar to you, but add one line to rotate root.right too:

/**
* Definition for a binary tree node.
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode(int x) { val = x; }
* }
*/
class Solution {
public TreeNode upsideDownBinaryTree(TreeNode root) {
if (root == null) {
return null;
}
if (root.left == null) {
return root;
}
TreeNode newRoot = upsideDownBinaryTree(root.left);
TreeNode newLeft = upsideDownBinaryTree(root.right); // This line rotate the right node
root.left.left = newLeft;
root.left.right = root;
root.left = null;
root.right = null;
return newRoot;
}
}

Both of our solutions can pass the OJ, I just want to know if there any parts I misunderstand.