175. 翻转二叉树

175. 翻转二叉树

翻转一棵二叉树

您在真实的面试中是否遇到过这个题?

Yes

样例

  1         1
 / \       / \
2   3  => 3   2
   /       \
  4         4

挑战

标签

AC代码:

class Solution {
public:
    /*
     * @param root: a TreeNode, the root of the binary tree
     * @return: nothing
     */
    void invertBinaryTree(TreeNode * root) {
        // write your code here
        if(root == NULL)
                {return;}
        else{
            TreeNode* node = root->left;  
            root->left = root->right;  
            root->left = root->right;  
            root->right = node;  
          
            invertBinaryTree( root->left );  
            invertBinaryTree( root->right ); 
        }
    }
};
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 去年二叉树算法的事情闹的沸沸扬扬,起因是Homebrew 的作者 @Max Howell 在 twitter 上发...
    Masazumi柒阅读 1,636评论 0 8
  • 本文转自 http://www.cnblogs.com/manji/p/4903990.html二叉树-****你...
    doublej_yjj阅读 696评论 0 8
  • 二叉树-你必须要懂!(二叉树相关算法实现-iOS) http://www.cnblogs.com/manji/p/...
    汉秋阅读 1,895评论 0 16
  • 1.什么是二叉树? 在计算机科学中,二叉树是每个节点最多有两个子树的树结构。通常子树被称作“左子树”和“右子树”,...
    zcaaron阅读 1,298评论 2 15
  • 树的概述 树是一种非常常用的数据结构,树与前面介绍的线性表,栈,队列等线性结构不同,树是一种非线性结构 1.树的定...
    Jack921阅读 4,517评论 1 31