[leetcode]226. Invert Binary Tree
Analysis
厉害的人总是那么的厉害呀~—— [菜鸡反省中~]
Invert a binary tree.
翻转二叉树,递归解决就行了。
Implement
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
class Solution {
public:
TreeNode* invertTree(TreeNode* root) {
if(root == NULL)
return root;
TreeNode* t = root->left;
root->left = root->right;
root->right = t;
invertTree(root->left);
invertTree(root->right);
return root;
}
};