Clean C++ Solution with Queue, Easy to Understand and beats 100% Users
Intuition\nThe idea is to traverse the tree level by level, using a queue to manage nodes at each level. For every level, nodes\' values are collected, and for 
# Intuition\nThe idea is to traverse the tree level by level, using a queue to manage nodes at each level. For every level, nodes\' values are collected, and for odd levels, the collected values are reversed to achieve the zigzag pattern.\n\n# Approach\n1. **Initial Checks and Setup :**\n- If the root is null, return an empty vector.\n \n- Initialize a queue to store the nodes to be processed at each level, starting with the root.\n \n2. **Level Order Traversal :**\n- Use a while loop to process nodes level by level until the queue is empty.\n \n- For each level, determine the number of nodes at that level (l = q.size()).\n- Use a for loop to iterate through all nodes at the current level:\na) Pop the front node from the queue.\nb) Append its value to a temporary vector (ans).\nc) Push its left and right children to the queue if they exist.\n\n3. **Collecting Results :**\n- Append the temporary vector (ans) containing the current level\'s node values to the result vector (v).\n\n4. **Zigzag Pattern :**\n- After completing the level order traversal, iterate through the result vector.\n- Reverse the node values for every odd-indexed level to achieve the zigzag pattern.\n\n5. **Return the Result :**\n- Return the result vector (v) containing the zigzag level order traversal.\n\n# Complexity\n- Time complexity:\nO(n)\n\n- Space complexity:\nO(n)\n\n# Code\n```\nclass Solution {\npublic:\n    vector<vector<int>> v;\n    vector<vector<int>> zigzagLevelOrder(TreeNode* root) {\n        if(!root) return v;\n        queue<TreeNode*> q;\n        q.push(root);\n        \n        while(q.size()>0){\n            vector<int> ans;\n            int l=q.size();\n            for(int i=0;i<l;i++){\n                TreeNode* temp=q.front();\n                q.pop();\n                ans.push_back(temp->val);\n                if(temp->left) q.push(temp->left);\n                if(temp->right) q.push(temp->right);\n            }\n            v.push_back(ans);\n        }\n        for(int i=0;i<v.size();i++){\n            if(i%2==1) reverse(v[i].begin(),v[i].end());\n        }\n        return v;\n    }\n};\n```
['Array', 'Tree', 'Breadth-First Search', 'Queue', 'Binary Tree', 'C++']