Class Solution
java.lang.Object
g0901_1000.s0923_3sum_with_multiplicity.Solution
923 - 3Sum With Multiplicity.<p>Medium</p>
<p>Given an integer array <code>arr</code>, and an integer <code>target</code>, return the number of tuples <code>i, j, k</code> such that <code>i < j < k</code> and <code>arr[i] + arr[j] + arr[k] == target</code>.</p>
<p>As the answer can be very large, return it <strong>modulo</strong> <code>10<sup>9</sup> + 7</code>.</p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> arr = [1,1,2,2,3,3,4,4,5,5], target = 8</p>
<p><strong>Output:</strong> 20</p>
<p><strong>Explanation:</strong></p>
<pre><code> Enumerating by the values (arr[i], arr[j], arr[k]):
(1, 2, 5) occurs 8 times;
(1, 3, 4) occurs 8 times;
(2, 2, 4) occurs 2 times;
(2, 3, 3) occurs 2 times.
</code></pre>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> arr = [1,1,2,2,2,2], target = 5</p>
<p><strong>Output:</strong> 12</p>
<p><strong>Explanation:</strong></p>
<p>arr[i] = 1, arr[j] = arr[k] = 2 occurs 12 times:</p>
<p>We choose one 1 from [1,1] in 2 ways,</p>
<p>and two 2s from [2,2,2,2] in 6 ways.</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>3 <= arr.length <= 3000</code></li>
<li><code>0 <= arr[i] <= 100</code></li>
<li><code>0 <= target <= 300</code></li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
threeSumMulti
public int threeSumMulti(int[] arr, int target)
-