20240307 Finished
This commit is contained in:
parent
59e9219040
commit
08054627f5
|
@ -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;
|
||||
mod p2917_find_the_k_or_of_an_array;
|
||||
mod p2575_find_the_divisibility_array_of_a_string;
|
41
src/problem/p2575_find_the_divisibility_array_of_a_string.rs
Normal file
41
src/problem/p2575_find_the_divisibility_array_of_a_string.rs
Normal 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));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user