rs: add «1700. Number of Students Unable to Eat Lunch»
Signed-off-by: Matej Focko <mfocko@redhat.com>
This commit is contained in:
parent
1812c2121d
commit
9baf18d1a6
1 changed files with 20 additions and 0 deletions
20
rs/number-of-students-unable-to-eat-lunch.rs
Normal file
20
rs/number-of-students-unable-to-eat-lunch.rs
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
impl Solution {
|
||||||
|
pub fn count_students(students: Vec<i32>, sandwiches: Vec<i32>) -> i32 {
|
||||||
|
let mut students_by_sandwiches = vec![0; 2];
|
||||||
|
for student in &students {
|
||||||
|
students_by_sandwiches[*student as usize] += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
for sandwich in &sandwiches {
|
||||||
|
let idx = *sandwich as usize;
|
||||||
|
|
||||||
|
if students_by_sandwiches[idx] <= 0 {
|
||||||
|
return students_by_sandwiches[(idx + 1) % 2];
|
||||||
|
}
|
||||||
|
|
||||||
|
students_by_sandwiches[idx] -= 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
0
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue