923. 3Sum With Multiplicity Medium
1/**
2 * [923] 3Sum With Multiplicity
3 *
4 * Given an integer array arr, and an integer target, return the number of tuples i, j, k such that i < j < k and arr[i] + arr[j] + arr[k] == target.
5 * As the answer can be very large, return it modulo 10^9 + 7.
6 *
7 * Example 1:
8 *
9 * Input: arr = [1,1,2,2,3,3,4,4,5,5], target = 8
10 * Output: 20
11 * Explanation:
12 * Enumerating by the values (arr[i], arr[j], arr[k]):
13 * (1, 2, 5) occurs 8 times;
14 * (1, 3, 4) occurs 8 times;
15 * (2, 2, 4) occurs 2 times;
16 * (2, 3, 3) occurs 2 times.
17 *
18 * Example 2:
19 *
20 * Input: arr = [1,1,2,2,2,2], target = 5
21 * Output: 12
22 * Explanation:
23 * arr[i] = 1, arr[j] = arr[k] = 2 occurs 12 times:
24 * We choose one 1 from [1,1] in 2 ways,
25 * and two 2s from [2,2,2,2] in 6 ways.
26 *
27 * Example 3:
28 *
29 * Input: arr = [2,1,3], target = 6
30 * Output: 1
31 * Explanation: (1, 2, 3) occured one time in the array so we return 1.
32 *
33 *
34 * Constraints:
35 *
36 * 3 <= arr.length <= 3000
37 * 0 <= arr[i] <= 100
38 * 0 <= target <= 300
39 *
40 */
41pub struct Solution {}
42
43// problem: https://leetcode.com/problems/3sum-with-multiplicity/
44// discuss: https://leetcode.com/problems/3sum-with-multiplicity/discuss/?currentPage=1&orderBy=most_votes&query=
45
46// submission codes start here
47
48impl Solution {
49 pub fn three_sum_multi(arr: Vec<i32>, target: i32) -> i32 {
50 0
51 }
52}
53
54// submission codes end
55
56#[cfg(test)]
57mod tests {
58 use super::*;
59
60 #[test]
61 fn test_923() {
62 }
63}
64
Back
© 2025 bowen.ge All Rights Reserved.