[思路]:
讲一个数左右子树互换;
- 使用深度遍历;
TreeNode* invertTree(TreeNode* root) {
if(!root)return nullptr;
TreeNode* temp = root->left;
root->left = invertTree(root->right);
root->right = invertTree(temp);
return root;
}
网友评论