题目:
题解:
class Solution { public: vector> levelOrder(TreeNode* root) { queue que; vector > res; if (root != nullptr) que.push(root); while (!que.empty()) { vector tmp; for(int i = que.size(); i > 0; --i) { root = que.front(); que.pop(); tmp.push_back(root->val); if (root->left != nullptr) que.push(root->left); if (root->right != nullptr) que.push(root->right); } res.push_back(tmp); } return res; } };
还没有评论,来说两句吧...