<p>Given the <code>root</code> of a binary tree, return <em>the zigzag level order traversal of its nodes&#39; values</em>. (i.e., from left to right, then right to left for the next level and alternate between).</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2021/02/19/tree1.jpg" style="width: 277px; height: 302px;" />
<pre>
<strong>Input:</strong> root = [3,9,20,null,null,15,7]
<strong>Output:</strong> [[3],[20,9],[15,7]]
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> root = [1]
<strong>Output:</strong> [[1]]
</pre>

<p><strong class="example">Example 3:</strong></p>

<pre>
<strong>Input:</strong> root = []
<strong>Output:</strong> []
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li>The number of nodes in the tree is in the range <code>[0, 2000]</code>.</li>
	<li><code>-100 &lt;= Node.val &lt;= 100</code></li>
</ul>

class Solution {
public:
    vector<vector<int>> zigzagLevelOrder(TreeNode* root) {
        if (root == nullptr)
            return {};

        stack<TreeNode*> st1; // Stack for current level
        stack<TreeNode*> st2; // Stack for next level
        st1.push(root);
        vector<vector<int>> ans;
        vector<int> a;

        while (!st1.empty() || !st2.empty()) {
            if (!st1.empty()) {
                while (!st1.empty()) {
                    TreeNode* temp = st1.top();
                    st1.pop();
                    a.push_back(temp->val);
                    if (temp->left) {
                        st2.push(temp->left);
                    }
                    if (temp->right) {
                        st2.push(temp->right);
                    }
                }
            } else {
                while (!st2.empty()) {
                    TreeNode* temp = st2.top();
                    st2.pop();
                    a.push_back(temp->val);
                    if (temp->right) {
                        st1.push(temp->right);
                    }
                    if (temp->left) {
                        st1.push(temp->left);
                    }
                }
            }

            ans.push_back(a);
            a.clear();
        }
        return ans;
    }
};

13500