标签:class stat 题解 tree padding otto rgb nod art
题目:
Invert a binary tree.
4 / 2 7 / \ / 1 3 6 9to
4 / 7 2 / \ / 9 6 3 1解答:
遍历每个节点 直接交换他们的左右节点
代码:
public static TreeNode invertTree(TreeNode root) {
if(root!=null)
{
TreeNode temNode=root.left;
root.left=root.right;
root.right=temNode;
invertTree(root.left);
invertTree(root.right);
}
return root;
}LeetCode226 InvertBinaryTree Java题解
标签:class stat 题解 tree padding otto rgb nod art
原文地址:http://www.cnblogs.com/jhcelue/p/6806520.html