zoukankan      html  css  js  c++  java
  • 【leetcode❤python】107. Binary Tree Level Order Traversal II

    #-*- coding: UTF-8 -*-
    # 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 levelOrderBottom(self, root):
            """
            :type root: TreeNode
            :rtype: List[List[int]]
            """
            if root==None:
                return []
            resultslist=[[root.val]]
            currootlist=[root]
            
            while True:
                resultstmplist=[]
                curtmplist=[]
                for i in range(0,len(currootlist)):
                    cur=currootlist[i]
                    if cur.left!=None:
                        curtmplist.append(cur.left)
                        resultstmplist.append(cur.left.val)
                    if cur.right!=None:
                        curtmplist.append(cur.right)
                        resultstmplist.append(cur.right.val)
                
                if len(curtmplist)==0:
                    break
                resultslist.append(resultstmplist)
                currootlist=curtmplist
                
            resultslist.reverse()    
            return resultslist

  • 相关阅读:
    MVC是什么?
    Slice Header中的field_pic_flag的含义?
    Slice header 中的frame_num的含义?
    上下文管理器 contextlib
    mixin模式特点
    Flask中路由原理
    使用Docker搭建Django,Nginx,R,Python部署环境
    使用Docker+Jenkins自动构建部署
    Jenkins 关闭和重启
    使用pipenv管理python项目
  • 原文地址:https://www.cnblogs.com/kwangeline/p/5953475.html
Copyright © 2011-2022 走看看