题目:翻转一棵二叉树
样例:
1 1
/ \ / \
2 3 => 3 2
/ \
4 4
代码:
class Solution {
public:
/**
* @param root: a TreeNode, the root of the binary tree
* @return: nothing
*/
void invertBinaryTree(TreeNode *root) {
// write your code here
if(root==NULL) return;
else
{
TreeNode *t=root->left;
root->left=root->right;
root->right=t;
invertBinaryTree(root->left);
invertBinaryTree(root->right);
}
}
};