fastest C++ solution
class Solution {\npublic:\n    vector> zigzagLevelOrder(TreeNode* root) {\n      \n        vector> v;\n        \n        if(root==NULL)\n            return v;\n
class Solution {\npublic:\n    vector<vector<int>> zigzagLevelOrder(TreeNode* root) {\n      \n        vector<vector<int>> v;\n        \n        if(root==NULL)\n            return v;\n        queue <TreeNode *>q;\n        q.push(root);int flag=0;\n        while(!q.empty())\n        {    int n=q.size();\n             vector<int> ans;\n             for(int i=0;i<n;i++){\n             \n             TreeNode *temp=q.front();\n             q.pop();\n         \n             if(temp->left)q.push(temp->left);\n             if(temp->right)q.push(temp->right);\n             ans.push_back(temp->val);\n         }\n            \n        \n        \n        if(flag==1)\n        {\n            reverse(ans.begin(),ans.end());\n            flag=0;\n        }\n        else\n         {\n             flag=1;\n         }\n        v.push_back(ans);\n        \n        \n        }\n        return v;\n    }\n};
[]