翻转二叉树
递归法
class Solution { public: TreeNode* invertTree(TreeNode* root) { if(root == nullptr) return root; swap(root->left, root->right); //中 invertTree(root->left); //左 invertTree(root->right); //左 return root; } };
递归法和遍历二叉树思路类似,中左右 前序遍历法。
迭代法思路理清后补充
标签:right,return,invertTree,Day32,二叉树,root,LeetCode,刷题 From: https://www.cnblogs.com/tianmaster/p/16953816.html