版權(quán)聲明:本文為博主原創(chuàng)文章,未經(jīng)博主允許不得轉(zhuǎn)載轩拨。
難度:容易
要求:
翻轉(zhuǎn)一棵二叉樹(shù)
樣例
1 1
/ \ / \
2 3 => 3 2
/ \
4 4
思路:
/**
* @param root: a TreeNode, the root of the binary tree
* @return: nothing
*/
public void invertBinaryTree(TreeNode root) {
if(root == null){
return;
}
TreeNode node = root.left;
root.left = root.right;
root.right = node;
invertBinaryTree(root.left);
invertBinaryTree(root.right);
}