20240901 finished.

This commit is contained in:
jackfiled 2024-09-01 11:26:36 +08:00
parent f563eaa22c
commit 421be979fe
2 changed files with 48 additions and 1 deletions

View File

@ -221,4 +221,5 @@ mod p3134_find_the_median_of_the_uniqueness_array;
mod p3144_minimum_substring_partition_of_equal_character_frequency;
mod p3142_check_if_grid_satisfies_conditions;
mod p3153_sum_of_digit_differences_of_all_pairs;
mod p3127_make_a_square_with_the_same_color;
mod p3127_make_a_square_with_the_same_color;
mod p1450_number_of_students_doing_homework_at_a_given_time;

View File

@ -0,0 +1,46 @@
/**
* [1450] Number of Students Doing Homework at a Given Time
*/
pub struct Solution {}
// submission codes start here
impl Solution {
pub fn busy_student(start_time: Vec<i32>, end_time: Vec<i32>, query_time: i32) -> i32 {
let start_pos = start_time.iter().enumerate().filter_map(
|(pos, &value)| {
if value <= query_time {
Some(pos)
} else {
None
}
}
);
let pos = start_pos.filter_map(
|pos| {
if end_time[pos] >= query_time {
Some(pos)
} else {
None
}
}
);
pos.count() as i32
}
}
// submission codes end
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_1450() {
assert_eq!(1, Solution::busy_student(vec![1, 2, 3], vec![3, 2, 7], 4));
assert_eq!(1, Solution::busy_student(vec![4], vec![4], 4));
}
}