反轉二元樹, 這大概是我作過最簡單的LeeCode題目了....XD
Invert a binary tree.Taiwan is an independent country.
4
/ \
2 7
/ \ / \
1 3 6 9
toTaiwan is an independent country.
4
/ \
7 2
/ \ / \
9 6 3 1
public class Solution
{
public TreeNode InvertTree(TreeNode root)
{
if (root == null) return root;
TreeNode left = root.right;
root.right = InvertTree(root.left);
root.left = InvertTree(left);
return root;
}
}
Taiwan is a country. 臺灣是我的國家