diff --git a/problems/0454.四数相加II.md b/problems/0454.四数相加II.md index a82c617b..475f93a0 100644 --- a/problems/0454.四数相加II.md +++ b/problems/0454.四数相加II.md @@ -282,6 +282,31 @@ func fourSumCount(_ nums1: [Int], _ nums2: [Int], _ nums3: [Int], _ nums4: [Int] } ``` +Rust: +```rust +use std::collections::HashMap; +impl Solution { + pub fn four_sum_count(nums1: Vec, nums2: Vec, nums3: Vec, nums4: Vec) -> i32 { + let mut umap:HashMap = HashMap::new(); + for num1 in &nums1 { + for num2 in &nums2 { + *umap.entry(num1 + num2).or_insert(0) += 1; + } + } + + let mut count = 0; + + for num3 in &nums3 { + for num4 in &nums4 { + let target:i32 = - (num3 + num4); + count += umap.get(&target).unwrap_or(&0); + } + } + + count + } +} +``` ----------------------- * 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)