20250310 finished.
This commit is contained in:
parent
9d8a00e20a
commit
6a17490a79
|
@ -528,3 +528,5 @@ mod p2597_the_number_of_beautiful_subsets;
|
|||
mod p2234_maximum_total_beauty_of_the_gardens;
|
||||
|
||||
mod p2070_most_beautiful_item_for_each_query;
|
||||
|
||||
mod p2269_find_the_k_beauty_of_a_number;
|
||||
|
|
36
src/problem/p2269_find_the_k_beauty_of_a_number.rs
Normal file
36
src/problem/p2269_find_the_k_beauty_of_a_number.rs
Normal file
|
@ -0,0 +1,36 @@
|
|||
/**
|
||||
* [2269] Find the K-Beauty of a Number
|
||||
*/
|
||||
pub struct Solution {}
|
||||
|
||||
// submission codes start here
|
||||
|
||||
impl Solution {
|
||||
pub fn divisor_substrings(num: i32, k: i32) -> i32 {
|
||||
let k = k as usize;
|
||||
let num_str: Vec<char> = num.to_string().chars().collect();
|
||||
|
||||
(0..=num_str.len() - k)
|
||||
.into_iter()
|
||||
.map(|i| {
|
||||
(&num_str[i..i + k])
|
||||
.iter()
|
||||
.fold(0i32, |v, c| v * 10 + c.to_digit(10).unwrap() as i32)
|
||||
})
|
||||
.filter(|&v| v != 0 && num % v == 0)
|
||||
.count() as i32
|
||||
}
|
||||
}
|
||||
|
||||
// submission codes end
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_2269() {
|
||||
assert_eq!(2, Solution::divisor_substrings(240, 2));
|
||||
assert_eq!(2, Solution::divisor_substrings(430043, 2));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user