# Definition for a binary tree node.
# class TreeNode(object):
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = None class Solution(object):
def levelOrder(self, root):
"""
:type root: TreeNode
:rtype: List[List[int]]
"""
res=[] if root is None:
return res
level=0 rs=self.levelOrderRe(root,level,res) return rs
def levelOrderRe(self,tree,level,res):
if tree is None:
return res if len(res) < level+1:
res.append([])
res[level].append(tree.val)
res=self.levelOrderRe(tree.left,level+1,res)
res=self.levelOrderRe(tree.right,level+1,res)
return res

leetcode Binary Tree Level Order Traversal python的更多相关文章

  1. LeetCode:Binary Tree Level Order Traversal I II

    LeetCode:Binary Tree Level Order Traversal Given a binary tree, return the level order traversal of ...

  2. [leetcode]Binary Tree Level Order Traversal II @ Python

    原题地址:http://oj.leetcode.com/problems/binary-tree-level-order-traversal-ii/ 题意: Given a binary tree, ...

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

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

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

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

  5. LeetCode: Binary Tree Level Order Traversal 解题报告

    Binary Tree Level Order Traversal Given a binary tree, return the level order traversal of its nodes ...

  6. [Leetcode] Binary tree level order traversal ii二叉树层次遍历

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

  7. [LeetCode] Binary Tree Level Order Traversal 与 Binary Tree Zigzag Level Order Traversal,两种按层次遍历树的方式,分别两个队列,两个栈实现

    Binary Tree Level Order Traversal Given a binary tree, return the level order traversal of its nodes ...

  8. LeetCode——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——Binary Tree Level Order Traversal

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

随机推荐

  1. android gallery的使用

    1: xml <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"     xml ...

  2. MySQL之终端(Terminal)管理数据库、数据表、数据的基本操作(转)

    MySQL有很多的可视化管理工具,比如“mysql-workbench”和“sequel-pro-”. 现在我写MySQL的终端命令操作的文章,是想强化一下自己对于MySQL的理解,总会比使用图形化的 ...

  3. 从头开始-05.C语言中函数

    函数: 完成特定功能代码段 特点:函数只有调用的时候才会执行 定义格式:返回值类型 函数名称(形参类型 形参名称,...){ 语句; ...  } 函数参数 形式参数:在定义函数的时候,函数名后面小括 ...

  4. AndroidUI--SlidingMenu使用例子

    SlidingMenu简介: SlidingMenu的是一种比较新的设置界面或配置界面效果,在主界面左滑或者右滑出现设置界面,能方便的进行各种操作.目前有大量的应用都在使用这一效果.如Evernote ...

  5. c++11: <thread>学习

    <thread>头文件中包含thread类与this_thread命名空间,下面逐一介绍. thread类 1. 构造函数 (1)默认构造函数 thread() noexcept; 默认构 ...

  6. phpcms 任意位置获取用户头像

    主要拿到userid $_username = param::get_cookie('_username');//当前登录人用户名 $_userid = param::get_cookie('_use ...

  7. 在外部存储器上写入或读取文件(Environment类、File类的使用)

    1.Environment类 简单介绍:http://www.cnblogs.com/mengdd/p/3742623.html 详细介绍:http://www.2cto.com/kf/201408/ ...

  8. jupyter巨好玩-调试代码自动变文档

    有时候,我们写python程序,总是会出现各种错误,当酒过三巡,菜过五味,所有问题都解决了之后,我们就想把犯过的错误总结一下,以便日后查询.这时候问题来了,难道要一一重现一下? jupyter来了!一 ...

  9. Database.SetInitializer的几种参数

    一:数据库不存在时重新创建数据库 Database.SetInitializer<testContext>(new CreateDatabaseIfNotExists<testCon ...

  10. 图像 - 创建 头像V1.0

    byte[] logo //处理群头像信息 //byte[] logoByte = Convert.FromBase64String(logo); ////1.0 System.IO.MemorySt ...