Skip to content

Commit

Permalink
Update p3162
Browse files Browse the repository at this point in the history
  • Loading branch information
HuaHuaY committed Oct 10, 2024
1 parent 530009a commit 694c8e6
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Call test by running `cargo test p[xxx]_`.

## 现在可以公开的情报(Problems Solved)

### Easy(89)
### Easy(90)

- [1. Two Sum](src/leetcode/p1_two_sum)
- [9. Palindrome Number](src/leetcode/p9_palindrome_number)
Expand Down Expand Up @@ -98,6 +98,7 @@ Call test by running `cargo test p[xxx]_`.
- [2859. Sum of Values at Indices With K Set Bits](src/leetcode/p2859_sum_of_values_at_indices_with_k_set_bits)
- [2864. Maximum Odd Binary Number](src/leetcode/p2864_maximum_odd_binary_number)
- [2917. Find the K-or of an Array](src/leetcode/p2917_find_the_k_or_of_an_array)
- [3162. Find the Number of Good Pairs I](src/leetcode/p3162_find_the_number_of_good_pairs_i)

### Medium(192)

Expand Down
1 change: 1 addition & 0 deletions src/leetcode/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ pub mod p300_longest_increasing_subsequence;
pub mod p303_range_sum_query_immutable;
pub mod p30_substring_with_concatenation_of_all_words;
pub mod p310_minimum_height_trees;
pub mod p3162_find_the_number_of_good_pairs_i;
pub mod p31_next_permutation;
pub mod p32_longest_valid_parentheses;
pub mod p331_verify_preorder_serialization_of_a_binary_tree;
Expand Down
31 changes: 31 additions & 0 deletions src/leetcode/p3162_find_the_number_of_good_pairs_i/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
pub struct Solution;

impl Solution {
pub fn number_of_pairs(nums1: Vec<i32>, nums2: Vec<i32>, k: i32) -> i32 {
nums1
.into_iter()
.map(|x| nums2.iter().filter(|&&y| (x % (y * k)) == 0).count() as i32)
.sum::<i32>()
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test1() {
assert_eq!(
Solution::number_of_pairs([1, 3, 4].to_vec(), [1, 3, 4].to_vec(), 1),
5
);
}

#[test]
fn test2() {
assert_eq!(
Solution::number_of_pairs([1, 2, 4, 12].to_vec(), [2, 4].to_vec(), 3),
2
);
}
}

0 comments on commit 694c8e6

Please sign in to comment.