leetcode中的:二叉树的层次遍历ii
![d2af0f105779896cc7d9c4ca1e3a917e.png](https://i-blog.csdnimg.cn/blog_migrate/354c7b402bafa95734ab9b1a4245e534.jpeg)
class Solution: def levelOrderBottom(self, root: TreeNode) -> List[List[int]]: if not root: return None stack1 = [root] stack2 = [] ret = [] while stack1 or stack2: if stack1: tmpList = [] while stack1: tmp = stack1[0] tmpList.append(tmp.val) if tmp.left: stack2.append(tmp.left) if tmp.right: stack2.append(tmp.right) del stack1[0] ret.insert(0, tmpList) if stack2: tmpList = [] while stack2: tmp = stack2[0] tmpList.append(tmp.val) if tmp.left: stack1.append(tmp.left) if tmp.right: stack1.append(tmp.right) del stack2[0] ret.insert(0, tmpList) return ret