/**
* Definition of TreeNode:
* public class TreeNode {
* public int val;
* public TreeNode left, right;
* public TreeNode(int val) {
* this.val = val;
* this.left = this.right = null;
* }
* }
*/
public class Solution {
/**
* @param root: the root of binary tree
* @return: new root
*/
public TreeNode upsideDownBinaryTree(TreeNode root) {
// write your code here
if(root == null) {
return null;
}
if(root.left == null) {
return root;
}
TreeNode result = upsideDownBinaryTree(root.left);
//把root 左子树的左子树赋值为root的右子树 root左子树的右子树赋值为root本身;
root.left.left = root.right;
root.left.right = root;
root.left = null;
root.right = null;
return result;
}
}