#-*- 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
相关文章
- [LeetCode]Binary Tree Level Order Traversal
- LeetCode Binary Tree Level Order Traversal (按层收集元素)
- LeetCode算法题-Binary Tree Level Order Traversal II(Java实现)
- [LeetCode]题解(python):144-Binary Tree Preorder Traversal
- 【leetcode】Binary Tree Level Order Traversal I & II
- 【leetcode❤python】107. Binary Tree Level Order Traversal II
- LeetCode OJ:Binary Tree Level Order Traversal(二叉树的层序遍历)
- (二叉树 BFS) leetcode102. Binary Tree Level Order Traversal
- [LeetCode] Binary Tree Level Order Traversal 2
- [LeetCode]103. Binary Tree Zigzag Level Order Traversal--二叉树之字形遍历