Skip to content

Commit 25dae52

Browse files
committed
923
1 parent fe37052 commit 25dae52

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

Math/923.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)