[C++] [Using DEQUE] Runtime: 0 ms,Memory Usage: 12.2 MB.
\n/**\n * Definition for a binary tree node.\n * struct TreeNode {\n *     int val;\n *     TreeNode *left;\n *     TreeNode *right;\n *     TreeNode() : val(0)
```\n/**\n * Definition for a binary tree node.\n * struct TreeNode {\n *     int val;\n *     TreeNode *left;\n *     TreeNode *right;\n *     TreeNode() : val(0), left(nullptr), right(nullptr) {}\n *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n    vector<vector<int>> zigzagLevelOrder(TreeNode* root) {\n        vector<vector<int>> ans;\n        if(!root)\n            return ans;\n        deque<TreeNode*> dq;\n        dq.push_back(root);\n        bool isLTR = true;\n        while(!dq.empty()) {\n            int n = dq.size();\n            vector<int> currLevel;\n            if(isLTR) {\n                isLTR = false;\n                for(int i=0;i<n;++i) {\n                    auto curr = dq.front();\n                    dq.pop_front();\n                    currLevel.push_back(curr->val);\n                    if(curr->left)\n                        dq.push_back(curr->left);\n                    if(curr->right)\n                        dq.push_back(curr->right);\n                }\n            } else {\n                isLTR = true;\n                for(int i=0;i<n;++i) {\n                    auto curr = dq.back();\n                    dq.pop_back();\n                    currLevel.push_back(curr->val);\n                    if(curr->right)\n                        dq.push_front(curr->right);\n                    if(curr->left)\n                        dq.push_front(curr->left);\n                }\n            }\n            ans.push_back(currLevel);\n        }\n        return ans;\n    }\n};\n```
['Queue', 'C']