[刷题] 226 Invert Binary Tree

要求

  • 翻转一棵二叉树

实现

  • 翻转左右子树,交换左右子树的根节点
 1 class Solution {
 2 public:
 3     TreeNode* invertTree(TreeNode* root) {
 4         
 5         if( root == NULL )
 6             return NULL;
 7             
 8         invertTree( root->left );
 9         invertTree( root->right );
10         swap( root->left, root->right );
11         
12         return root;
13     }
14 };
View Code

相关

  • 100 Same Tree
  • 101 Symmetric Tree
  • 222 Count Complete Tree Nodes
  • 110 Balanced Binary Tree
posted @ 2020-04-11 11:08  cxc1357  阅读(104)  评论(0编辑  收藏  举报