diff --git a/src/problem/mod.rs b/src/problem/mod.rs index 47dfe5f..522b1e8 100644 --- a/src/problem/mod.rs +++ b/src/problem/mod.rs @@ -65,4 +65,5 @@ mod p2368_reachable_nodes_with_restrictions; mod p225_implement_stack_using_queues; mod p232_implement_queue_using_stacks; mod p1976_number_of_ways_to_arrive_at_destination; -mod p2917_find_the_k_or_of_an_array; \ No newline at end of file +mod p2917_find_the_k_or_of_an_array; +mod p2575_find_the_divisibility_array_of_a_string; \ No newline at end of file diff --git a/src/problem/p2575_find_the_divisibility_array_of_a_string.rs b/src/problem/p2575_find_the_divisibility_array_of_a_string.rs new file mode 100644 index 0000000..c03579e --- /dev/null +++ b/src/problem/p2575_find_the_divisibility_array_of_a_string.rs @@ -0,0 +1,41 @@ +/** + * [2575] Find the Divisibility Array of a String + */ +pub struct Solution {} + + +// submission codes start here + +impl Solution { + pub fn divisibility_array(word: String, m: i32) -> Vec { + let mut result = vec![0;word.len()]; + let mut now = 0; + let m = m as i64; + + for (index, c) in word.char_indices() { + let num = c.to_digit(10).unwrap() as i64; + now = now * 10 + num; + + if now % m == 0 { + result[index] = 1; + now = 0 + } else { + now = now % m; + } + } + + result + } +} + +// submission codes end + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_2575() { + assert_eq!(vec![1,1,0,0,0,1], Solution::divisibility_array("998244".to_owned(), 3)); + } +}