#-*- 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
相关文章
- 09-24leetcode 102 Binary Tree Level Order Traversal(DFS||BFS)
- 09-24【leetcode】Binary Tree Level Order Traversal I & II
- 09-24Leetcode 102 Binary Tree Level Order Traversal 二叉树+BFS
- 09-24leetcode Binary Tree Inorder Traversal python
- 09-24[LeetCode]题解(python):105-Construct Binary Tree from Preorder and Inorder Traversal
- 09-24103. Binary Tree Zigzag Level Order Traversal
- 09-24leetCode 103.Binary Tree Zigzag Level Order Traversal (二叉树Z字形水平序) 解题思路和方法
- 09-24[leetcode] 103 Binary Tree Zigzag Level Order Traversal (Medium)
- 09-24Leetcode#103 Binary Tree Zigzag Level Order Traversal
- 09-24[leetcode]103. Binary Tree Zigzag Level Order Traversal二叉树Z字形层序遍历