java 156. Binary Tree Upside Down.java
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了java 156. Binary Tree Upside Down.java相关的知识,希望对你有一定的参考价值。
/**
* Definition for a binary tree node.
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode(int x) { val = x; }
* }
*/
public class Solution {
public TreeNode upsideDownBinaryTree(TreeNode root) {
if (root == null || root.left == null && root.right == null) return root;
TreeNode res = upsideDownBinaryTree(root.left);
root.left.right = root;
root.left.left = root.right;
root.right = null;
root.left = null;
return res;
}
}
/*
[]
[1,2]
[1,2,3,4,5]
[1,2,3,4,5,null,null,6,7]
*/
以上是关于java 156. Binary Tree Upside Down.java的主要内容,如果未能解决你的问题,请参考以下文章
java 156. Binary Tree Upside Down.java
java 156. Binary Tree Upside Down.java
java 156. Binary Tree Upside Down.java
java 156. Binary Tree Upside Down.java
156. Binary Tree Upside Down
156. Binary Tree Upside Down