标签:evel solution cto lse while return order -- style
class Solution { public: vector<vector<int>> zigzagLevelOrder(TreeNode* root) { vector<vector<int>> V; if (root != NULL) { int i = 0; queue<TreeNode*> Q; Q.push(root); while (!Q.empty()) { vector<TreeNode*> T; vector<int> v; while (!Q.empty()) { TreeNode* node = Q.front(); Q.pop(); T.push_back(node); v.push_back(node->val); } if (i % 2 == 1) { vector<int> vv; for (int j = v.size() - 1; j >= 0; j--) { vv.push_back(v[j]); } V.push_back(vv); } else { V.push_back(v); } for (auto t : T) { if (t->left != NULL) { Q.push(t->left); } if (t->right != NULL) { Q.push(t->right); } } i++; } } return V; } };
标签:evel solution cto lse while return order -- style
原文地址:https://www.cnblogs.com/asenyang/p/9745209.html