Invert Binary Tree
该题比較简单。递归交换每个节点的左右子树就可以。
class Solution { public: TreeNode* invertTree(TreeNode* root) { if(root == NULL) return NULL; TreeNode* tmp = root -> left; root -> left = invertTree(root -> right); root -> right = invertTree(tmp); } };
该题比較简单。递归交换每个节点的左右子树就可以。
class Solution { public: TreeNode* invertTree(TreeNode* root) { if(root == NULL) return NULL; TreeNode* tmp = root -> left; root -> left = invertTree(root -> right); root -> right = invertTree(tmp); } };