lurenaa的博客

😂

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
class Solution {
public:
vector<vector<int>> levelOrder(TreeNode* root) {
vector<vector<int>> vec;
queue<TreeNode*> q;
if(root)
q.push(root);
while(q.size()) {
int sz = q.size();
vec.push_back({});
for(int i = 0; i < sz; ++i) {
auto top = q.front();
q.pop();
auto& vec1 = vec.back();
vec1.push_back(top->val);
if(top->left)
q.push(top->left);
if(top->right)
q.push(top->right);
}
}
return vec;
}
};

Accepted

34/34 cases passed (4 ms)

Your runtime beats 92.4 % of cpp submissions

Your memory usage beats 24.1 % of cpp submissions (14.2 MB)