Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit987a0aa

Browse files
authored
Merge pull requestneetcode-gh#2489 from derekjtong/Create-1700-number-of-students-unable-to-eat-lunch.cpp
Create 1700-number-of-students-unable-to-eat-lunch.cpp
2 parentsb0e1a66 +c3aa058 commit987a0aa

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
classSolution {
2+
public:
3+
intcountStudents(vector<int>& students, vector<int>& sandwiches) {
4+
queue<int> q1;
5+
for(int i =0; i < students.size(); i++) {
6+
q1.push(students[i]);
7+
}
8+
9+
int sandwichPos =0;
10+
int curr =0;
11+
while(!q1.empty() && curr <= q1.size()) {
12+
if(q1.front() == sandwiches[sandwichPos]) {
13+
q1.pop();
14+
sandwichPos++;
15+
curr =0;
16+
}else {
17+
q1.push(q1.front());
18+
q1.pop();
19+
}
20+
curr++;
21+
}
22+
return q1.size();
23+
}
24+
};

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp