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)

    ===

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

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

    ===

  • 相关阅读:
    mapreduce 本地调试需要注意的问题
    socket-----爬虫&&文件传输
    多个地点ping服务器
    linux grep命令详解
    关于真多核和加多核&线程由哪几部分组成
    内存溢出和内存泄漏
    指针和引用的区别
    Doxygen的使用,配置及实例
    【转】doxygen+graphviz生成工程中的类继承树及函数调用图
    转载--void指针(void *的用法)
  • 原文地址:https://www.cnblogs.com/wudanyang/p/13576965.html
Copyright © 2011-2022 走看看