4ms Concise DFS C++ Implementation
1 Calculate depth in each recursion.\n2 Switch directions for adding current value based on (depth % 2).\n\n      vector> zigzagLevelOrder(TreeNode root) {\n   
1 Calculate depth in each recursion.\n2 Switch directions for adding current value based on (depth % 2).\n\n      vector<vector<int>> zigzagLevelOrder(TreeNode* root) {\n            vector<vector<int>> rst;\n            traverse(root, 0, rst);\n            return rst;\n        }\n        \n    void traverse(TreeNode* root, int depth, vector<vector<int>> & rst) {\n        if (!root)\n            return;\n        if (rst.size() == depth) {\n            vector<int> temp;\n            rst.push_back(temp);\n        }\n        if (depth % 2 == 0)   \n            rst[depth].push_back(root ->val);\n        else{\n            rst[depth].insert(rst[depth].begin(), root -> val);   \n        }\n        traverse(root -> left, depth + 1, rst);  \n        traverse(root -> right, depth  +1, rst);\n    }
['C++']