# Zig-Zag Level Order Traversal of a Binary Tree (Leetcode 103)

Problem Link: <https://leetcode.com/problems/binary-tree-zigzag-level-order-traversal/>

```python
class Solution:
    def zigzagLevelOrder(self, root: Optional[TreeNode]) -> List[List[int]]:
        if(root is None):
            return []
        q=[root]
        ans=[]
        c=1
        while(len(q)>0):
            temp=[]
            for i in range(len(q)):
                node=q.pop()
                if(node.left is not None):
                    q.insert(0,node.left)
                if(node.right is not None):
                    q.insert(0,node.right)
                temp.append(node.val)
            if(c%2==0):
                ans.append(temp[::-1])
            else:
                ans.append(temp)
            c+=1
        return ans
```
