电子政务服务网站建设,网站域名免费,下载个人简历直接填写,闵行北京网站建设LeetCode | 226. 翻转二叉树
OJ链接 不为空就翻转#xff0c;空空就停止翻转左子树的节点给了右子树右子树的节点给了左就完成了翻转
struct TreeNode* invertTree(struct TreeNode* root) {//不为空就进行翻转if(root){//翻转struct TreeNode* tmp root-left;root-空空就停止翻转左子树的节点给了右子树右子树的节点给了左就完成了翻转
struct TreeNode* invertTree(struct TreeNode* root) {//不为空就进行翻转if(root){//翻转struct TreeNode* tmp root-left;root-left root-right;root-right tmp;//遍历左子树和右子树invertTree(root-left);invertTree(root-right);}//返回根节点return root;
}