val = $value; } * } */ class Solution { private $vals = []; /** * @param TreeNode $root * @return Integer[][] */ function levelOrderBottom($root) { $this->preOrder($root, 0); return array_reverse($this->vals); } function preOrder($node, $level){ if(is_null($node)){ return; } if(!isset($this->vals[$level])){ $this->vals[$level] = []; } $this->vals[$level][] = $node->val; if($node->left){ $this->preOrder($node->left, $level+1); } if($node->right){ $this->preOrder($node->right, $level+1); } } }

Leetcode PHP题解--D125 107. Binary Tree Level Order Traversal II的更多相关文章

  1. 102/107. Binary Tree Level Order Traversal/II

    原文题目: 102. Binary Tree Level Order Traversal 107. Binary Tree Level Order Traversal II 读题: 102. 层序遍历 ...

  2. 【LeetCode】107. Binary Tree Level Order Traversal II (2 solutions)

    Binary Tree Level Order Traversal II Given a binary tree, return the bottom-up level order traversal ...

  3. 【一天一道LeetCode】#107. Binary Tree Level Order Traversal II

    一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 来源: htt ...

  4. Java for LeetCode 107 Binary Tree Level Order Traversal II

    Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left ...

  5. LeetCode 107 Binary Tree Level Order Traversal II(二叉树的层级顺序遍历2)(*)

    翻译 给定一个二叉树,返回从下往上遍历经过的每一个节点的值. 从左往右,从叶子到节点. 比如: 给定的二叉树是 {3,9,20,#,#,15,7}, 3 / \ 9 20 / \ 15 7 返回它从下 ...

  6. [LeetCode] 107. Binary Tree Level Order Traversal II 二叉树层序遍历 II

    Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left ...

  7. (二叉树 BFS) leetcode 107. Binary Tree Level Order Traversal II

    Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left ...

  8. 【Leetcode】【Easy】Binary Tree Level Order Traversal II

    Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left ...

  9. [LeetCode]题解(python):107 Binary Tree Level Order Traversal II

    题目来源 https://leetcode.com/problems/binary-tree-level-order-traversal-ii/ Given a binary tree, return ...

随机推荐

  1. day03 每日一行

    day03 每日一行 问题描述 用列表解释式 .生成器表达式实现 字典列表为: [{'first': 'john', 'last': 'smith', 'email': 'jsmith@exsampl ...

  2. 10.redis cluster介绍与gossip协议

    一.redis cluster 介绍 自动将数据进行分片,每个 master 上放一部分数据 提供内置的高可用支持,部分 master 不可用时,还是可以继续工作的 redis cluster架构下的 ...

  3. 基于django快速开发一个网站(一)

    基于django快速开发一个网站(一) *  创建虚拟环境.基于虚拟环境创建django==2.0.0和图片加载库和mysql数据库驱动 1. 创建目录并创建虚拟环境 ╰$ mkdir Cornuco ...

  4. 每日一道 LeetCode (41):阶乘后的零

    每天 3 分钟,走上算法的逆袭之路. 前文合集 每日一道 LeetCode 前文合集 代码仓库 GitHub: https://github.com/meteor1993/LeetCode Gitee ...

  5. Zookeeper源码解读

    1.1. 客户端源码 1.1.1. 总体流程 启动客户端 zkCli.sh文件里面的配置 实际运行 public static void main(String args[]) throws Keep ...

  6. Java使用JDBC连接Oracle数据库

    import java.sql.Connection; import java.sql.Driver; import java.sql.DriverManager; /** * @author liu ...

  7. FFmpeg开发笔记(三):ffmpeg介绍、windows编译以及开发环境搭建

    前言   本篇章是对之前windows环境的补充,之前windows的是无需进行编译的,此篇使用源码进行编译,版本就使用3.4.8.   FFmpeg简介   FFmpeg是领先的多媒体框架,能够解码 ...

  8. 学习go的一些笔记

    反射 reflect type CfgSt struct{ Match *int64 `ini:"match"` Desc string `ini:"desc" ...

  9. CTF-BugKu-WEB-1-20

    2020.09.17 全面复习web,给自己定个目标,后天之前结束BugKu-Web,开始逆向. 经验教训 php弱等于用于绕过==,弱等于之前会把等号两边转化为同一类型变量: 全局变量全局变量全局变 ...

  10. apisix网关-构建docker镜像构建及插件化开发

    高能劝退:lua开发,适合小白看!!! 前段时间有个项目,用的java程序做网关,压测tps只有1k多点,惨不忍睹. 后来公司有个大佬改用apisix做网关,tps飙升到1w多. 于是对神奇的apis ...