交换二叉树的左右子树C加加
C++代码如下:
class Solution {
public:
TreeNode* invertTree(TreeNode* root) {
if (!root) return nullptr;
swap(root->left, root->right);
invertTree(root->left);
invertTree(root->right);
return root;
}
};
原文地址: https://www.cveoy.top/t/topic/0F2 著作权归作者所有。请勿转载和采集!