# -*- coding:utf-8 -*- # class TreeNode: # def __init__(self, x): # self.val = x # self.left = None # self.right = None classSolution: defPrint(self, pRoot): # write code here result=[] ifnot pRoot: return result
queue=[pRoot] while queue: value=[] for i in range(len(queue)): node=queue.pop(0) value.append(node.val) if node.left: queue.append(node.left) if node.right: queue.append(node.right) result.append(value) for i in range(len(result)): if i%2: result[i].reverse() return result