20240307 Finished

This commit is contained in:
jackfiled 2024-03-07 10:17:45 +08:00
parent 59e9219040
commit 08054627f5
2 changed files with 43 additions and 1 deletions

View File

@ -66,3 +66,4 @@ mod p225_implement_stack_using_queues;
mod p232_implement_queue_using_stacks; mod p232_implement_queue_using_stacks;
mod p1976_number_of_ways_to_arrive_at_destination; mod p1976_number_of_ways_to_arrive_at_destination;
mod p2917_find_the_k_or_of_an_array; mod p2917_find_the_k_or_of_an_array;
mod p2575_find_the_divisibility_array_of_a_string;

View File

@ -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<i32> {
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));
}
}