Skip to content

Commit 7203cf7

Browse files
add 923
1 parent 0266257 commit 7203cf7

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,7 @@ _If you like this project, please leave me a star._ ★
396396
|931|[Minimum Falling Path Sum](https://leetcode.com/problems/minimum-falling-path-sum/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_931.java) | |Medium|Dynamic Programming
397397
|929|[Unique Email Addresses](https://leetcode.com/problems/unique-email-addresses/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_929.java) | |Easy|
398398
|925|[Long Pressed Name](https://leetcode.com/problems/long-pressed-name/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_925.java) | |Easy|
399+
|923|[3Sum With Multiplicity](https://leetcode.com/problems/3sum-with-multiplicity/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_923.java) | |Medium|Two Pointers
399400
|922|[Sort Array By Parity II](https://leetcode.com/problems/sort-array-by-parity-ii/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_922.java) | |Easy|
400401
|921|[Minimum Add to Make Parentheses Valid](https://leetcode.com/problems/minimum-add-to-make-parentheses-valid/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_921.java) | |Medium|Stack, Greedy
401402
|917|[Reverse Only Letters](https://leetcode.com/problems/reverse-only-letters/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_917.java) | |Easy|
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package com.fishercoder.solutions;
2+
3+
import java.util.HashMap;
4+
import java.util.Map;
5+
6+
public class _923 {
7+
public static class Solution1 {
8+
public int threeSumMulti(int[] A, int target) {
9+
int MOD = 1000000007;
10+
Map<Integer, Long> map = new HashMap<>();
11+
for (int num : A) {
12+
map.put(num, map.getOrDefault(num, 0L) + 1);
13+
}
14+
long result = 0;
15+
for (int num1 : map.keySet()) {
16+
for (int num2 : map.keySet()) {
17+
int num3 = target - num1 - num2;
18+
if (map.containsKey(num3)) {
19+
Long count1 = map.get(num1);
20+
Long count2 = map.get(num2);
21+
Long count3 = map.get(num3);
22+
if (num1 == num2 && num1 == num3) {
23+
result = (result + (count1 * (count1 - 1) * (count1 - 2) / 6)) % MOD;
24+
} else if (num1 == num2 && num1 != num3) {
25+
result = (result + (count1 * (count1 - 1) / 2) * count3) % MOD;
26+
} else if (num1 < num2 && num2 < num3) {
27+
result = (result + count1 * count2 * count3) % MOD;
28+
}
29+
}
30+
}
31+
}
32+
return (int) result;
33+
}
34+
}
35+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.fishercoder;
2+
3+
import com.fishercoder.solutions._923;
4+
import org.junit.BeforeClass;
5+
import org.junit.Test;
6+
7+
import static org.junit.Assert.assertEquals;
8+
9+
public class _923Test {
10+
private static _923.Solution1 solution1;
11+
12+
@BeforeClass
13+
public static void setup() {
14+
solution1 = new _923.Solution1();
15+
}
16+
17+
@Test
18+
public void test1() {
19+
assertEquals(20, solution1.threeSumMulti(new int[]{1, 1, 2, 2, 3, 3, 4, 4, 5, 5}, 8));
20+
}
21+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy