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() {} +}