We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent fe37052 commit 25dae52Copy full SHA for 25dae52
Math/923.md
@@ -0,0 +1,33 @@
1
+## 3Sum With Multiplicity
2
+
3
+#### Description
4
5
+[link](https://leetcode.com/problems/3sum-with-multiplicity/)
6
7
+---
8
9
+#### Solution
10
11
+- See Code
12
13
14
15
+#### Code
16
17
+> Complexity T : O(n) M : O(n)
18
19
+```python
20
+class Solution:
21
+ def threeSumMulti(self, arr: List[int], target: int) -> int:
22
+ cnt, ans = collections.Counter(arr), 0
23
+ for i in cnt:
24
+ for j in cnt:
25
+ k = target - i - j
26
+ if i == j == k:
27
+ ans += cnt[i] * (cnt[i] - 1) * (cnt[i] - 2) // 6
28
+ elif i == j:
29
+ ans += cnt[i] * (cnt[i] - 1) // 2 * cnt[k]
30
+ elif i < j < k:
31
+ ans += cnt[i] * cnt[j] * cnt[k]
32
+ return ans % (10**9 + 7)
33
+```
0 commit comments