From d7a1bd1e1b9fa59ea36744e18f2e1c9f47aa84fb Mon Sep 17 00:00:00 2001 From: jackfiled Date: Sun, 18 Aug 2024 14:49:55 +0800 Subject: [PATCH] 20240818 Finished --- src/problem/mod.rs | 3 +- .../p551_student_attendance_record_i.rs | 49 +++++++++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 src/problem/p551_student_attendance_record_i.rs diff --git a/src/problem/mod.rs b/src/problem/mod.rs index 0a6795f..8900e6a 100644 --- a/src/problem/mod.rs +++ b/src/problem/mod.rs @@ -207,4 +207,5 @@ mod p123_best_time_to_buy_and_sell_stock_iii; mod p188_best_time_to_buy_and_sell_stock_iv; mod p221_maximal_square; mod p3117_minimum_sum_of_values_by_dividing_array; -mod p3137_minimum_number_of_operations_to_make_word_k_periodic; \ No newline at end of file +mod p3137_minimum_number_of_operations_to_make_word_k_periodic; +mod p551_student_attendance_record_i; diff --git a/src/problem/p551_student_attendance_record_i.rs b/src/problem/p551_student_attendance_record_i.rs new file mode 100644 index 0000000..cad5eec --- /dev/null +++ b/src/problem/p551_student_attendance_record_i.rs @@ -0,0 +1,49 @@ +/** + * [551] Student Attendance Record I + */ +pub struct Solution {} + +// submission codes start here + +impl Solution { + pub fn check_record(s: String) -> bool { + let s: Vec = s.chars().collect(); + let mut late_count = 0; + let mut absent_count = 0; + + for c in s { + match c { + 'A' => { + absent_count += 1; + late_count = 0; + + if absent_count >= 2 { + return false; + } + }, + 'L' => { + late_count += 1; + + if late_count >= 3 { + return false; + } + }, + _ => { + late_count = 0; + } + } + } + + true + } +} + +// submission codes end + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_551() {} +}