3.9刷题记录 Invert Binary Tree(226)
作者:互联网
运用一个递归进行二叉树的翻转,很基本的题目。、
class Solution { public: TreeNode* invertTree(TreeNode* root) { if (root == nullptr) { return nullptr; } TreeNode*left=invertTree(root->left); TreeNode*right=invertTree(root->right); root->left=right; root->right=left; return root; } };
标签:Binary,right,TreeNode,invertTree,Invert,Tree,return,root,left 来源: https://www.cnblogs.com/zhangdalao/p/14506059.html