20241010 finished.
This commit is contained in:
parent
63b8f77bfc
commit
bb6c1b09fe
|
@ -259,3 +259,4 @@ mod p2187_minimum_time_to_complete_trips;
|
|||
mod p871_minimum_number_of_refueling_stops;
|
||||
mod p1436_destination_city;
|
||||
mod p3171_find_subarray_with_bitwise_or_closest_to_k;
|
||||
mod p3162_find_the_number_of_good_pairs_i;
|
45
src/problem/p3162_find_the_number_of_good_pairs_i.rs
Normal file
45
src/problem/p3162_find_the_number_of_good_pairs_i.rs
Normal file
|
@ -0,0 +1,45 @@
|
|||
/**
|
||||
* [3162] Find the Number of Good Pairs I
|
||||
*/
|
||||
pub struct Solution {}
|
||||
|
||||
|
||||
// submission codes start here
|
||||
|
||||
impl Solution {
|
||||
pub fn number_of_pairs(nums1: Vec<i32>, nums2: Vec<i32>, k: i32) -> i32 {
|
||||
let nums1: Vec<i32> = nums1.into_iter().filter_map(|x| {
|
||||
if x % k == 0 {
|
||||
Some(x / k)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}).collect();
|
||||
|
||||
let mut result = 0;
|
||||
|
||||
for &num in nums1.iter() {
|
||||
for &num2 in nums2.iter() {
|
||||
if num % num2 == 0 {
|
||||
result += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
result
|
||||
}
|
||||
}
|
||||
|
||||
// submission codes end
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_3162() {
|
||||
assert_eq!(5, Solution::number_of_pairs(vec![1, 3, 4], vec![1, 3, 4], 1));
|
||||
assert_eq!(2, Solution::number_of_pairs(vec![1, 2, 4, 12], vec![2, 4], 3));
|
||||
assert_eq!(1, Solution::number_of_pairs(vec![2, 12], vec![4, 3], 4));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user