Skip to content

Commit a827cf4

Browse files
committed
Create 1700-NumberOfStudentsUnableToEatLunch.cpp
1 parent ca7e4e0 commit a827cf4

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Solution {
2+
public:
3+
int countStudents(vector<int>& students, vector<int>& sandwiches) {
4+
int a(0), b(0);
5+
for(int p = 0; p < students.size(); p++){
6+
a += (!students[p]);
7+
b += students[p];
8+
}
9+
10+
for(int p = 0; p < sandwiches.size(); p++){
11+
if(sandwiches[p]){--b; if(b < 0){return a;}}
12+
else{--a; if(a < 0){return b;}}
13+
}
14+
15+
return 0;
16+
}
17+
};

0 commit comments

Comments
 (0)