[leetcode] Invert binary tree.
Invert a binary tree.
class Solution { public: TreeNode* invertTree(TreeNode* root) { TreeNode* temp; if(root) { temp=root->left; root->left=root->right; root->right=temp; if(root->left) invertTree(root->left); if(root->right) invertTree(root->right); } return root; } };
1. 错:把if用成while。while和递归可以互换