zoukankan      html  css  js  c++  java
  • 226. 翻转二叉树-leetcode

    226. 翻转二叉树-leetcode

    226. 翻转二叉树-leetcode

    Table of Contents

    2 代码

    /**
     * Definition for a binary tree node.
     * class TreeNode {
     *     public $val = null;
     *     public $left = null;
     *     public $right = null;
     *     function __construct($value) { $this->val = $value; }
     * }
     */
    class Solution {
    
        /**
         * @param TreeNode $root
         * @return TreeNode
         */
        function invertTree($root) {
        if (empty($root)) {
            return $root;
        }
    
        $tmp = $root->left;
        $root->left = $root->right;
        $root->right = $tmp;
    
        $this->invertTree($root->left);
        $this->invertTree($root->right);
        return $root;
        }
    }
    

    简单题,但是可以不用递归解题 广度优先搜索的思想(Breadth-fist Search, BFS)也可以解题

    ===

    作者: 吴丹阳 https://www.cnblogs.com/wudanyang

    更新时间: 2020-08-30 Sun 23:34

    Emacs 27.1 (Org mode 9.3.7)

    ===

    天行健,君子以自强不息。

    地势坤,君子以厚德载物。

    ===

  • 相关阅读:
    lilntcode-508-摆动排序
    lintcode-501-迷你推特
    lintcode-496-玩具工厂
    lintcode-491-回文数
    lintcode-488-快乐数
    lintcode-480-二叉树的所有路径
    lintcode-248-统计比给定整数小的数的个数
    ubuntu 镜像站部署
    [转发]以我的亲身经历为例,告诉大家写简历和面试的技巧(面向高级开发和架构师)
    镜像站nginx
  • 原文地址:https://www.cnblogs.com/wudanyang/p/13576965.html
Copyright © 2011-2022 走看看