2018-11-08 leetcode Binary Tree Zigzag Level Order Traversal Binary Tree Zigzag Level Order TraversalBinary Search Version - 36ms 123456789101112131415161718192021222324252627282930313233343536# Definition for a binary tree node.# class TreeNode:# def __init__(self, x):# self.val = x# self.left = None# self.right = Noneclass Solution: def zigzagLevelOrder(self, root): """ :type root: TreeNode :rtype: List[List[int]] """ if not root: return [] queue = [root] res = [] level = 0 while queue: level += 1 temp = [] tempq = [] for node in queue: temp.append(node.val) if node.left: tempq.append(node.left) if node.right: tempq.append(node.right) queue = tempq if level % 2 == 0 : temp = temp[::-1] res.append(temp) return res leet code Newer Letter Combinations of a Phone Number Older Perfect Squares