```
class Solution:
# @param {TreeNode} root
# @return {integer[][]}
def zigzagLevelOrder(self, root):
if not root:
return []
prev, curr, result, flag = [root, ], [root, ], [], -1
while curr:
flag *= -1
result.append([node.val for node in curr[::flag]])
curr = []
while prev:
node = prev.pop(0)
if node.left:
curr.append(node.left)
if node.right:
curr.append(node.right)
prev = curr
return result
```