[刷题] 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
原文地址:https://www.cnblogs.com/cxc1357/p/12678178.html