Skip to content

Commit b63d865

Browse files
add 1726
1 parent 339526f commit b63d865

File tree

3 files changed

+65
-0
lines changed

3 files changed

+65
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ _If you like this project, please leave me a star._ ★
88

99
| # | Title | Solutions | Video | Difficulty | Tag
1010
|-----|----------------|---------------|--------|-------------|-------------
11+
|1726|[Tuple with Same Product](https://leetcode.com/problems/tuple-with-same-product/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1726.java) ||Medium|Array|
1112
|1725|[Number Of Rectangles That Can Form The Largest Square](https://leetcode.com/problems/number-of-rectangles-that-can-form-the-largest-square/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1725.java) ||Easy|Greedy|
1213
|1721|[Swapping Nodes in a Linked List](https://leetcode.com/problems/swapping-nodes-in-a-linked-list/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1721.java) ||Medium|LinkedList|
1314
|1720|[Decode XORed Array](https://leetcode.com/problems/decode-xored-array/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1720.java) ||Easy|Bit Manipulation|
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.fishercoder.solutions;
2+
3+
import java.util.HashMap;
4+
import java.util.Map;
5+
6+
public class _1726 {
7+
public static class Solution1 {
8+
public int tupleSameProduct(int[] nums) {
9+
Map<Integer, Integer> map = new HashMap<>();
10+
int count = 0;
11+
for (int i = 0; i < nums.length - 1; i++) {
12+
for (int j = i + 1; j < nums.length; j++) {
13+
int product = nums[i] * nums[j];
14+
count += 8 * map.getOrDefault(product, 0);
15+
map.put(product, map.getOrDefault(product, 0) + 1);
16+
}
17+
}
18+
return count;
19+
}
20+
21+
}
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package com.fishercoder;
2+
3+
import com.fishercoder.solutions._1726;
4+
import org.junit.BeforeClass;
5+
import org.junit.Test;
6+
7+
import static org.junit.Assert.assertEquals;
8+
9+
public class _1726Test {
10+
private static _1726.Solution1 solution1;
11+
12+
@BeforeClass
13+
public static void setup() {
14+
solution1 = new _1726.Solution1();
15+
}
16+
17+
@Test
18+
public void test1() {
19+
assertEquals(8, solution1.tupleSameProduct(new int[]{2, 3, 4, 6}));
20+
}
21+
22+
@Test
23+
public void test2() {
24+
assertEquals(16, solution1.tupleSameProduct(new int[]{1, 2, 4, 5, 10}));
25+
}
26+
27+
@Test
28+
public void test3() {
29+
assertEquals(40, solution1.tupleSameProduct(new int[]{2, 3, 4, 6, 8, 12}));
30+
}
31+
32+
@Test
33+
public void test4() {
34+
assertEquals(0, solution1.tupleSameProduct(new int[]{2, 3, 5, 7}));
35+
}
36+
37+
@Test
38+
public void test5() {
39+
assertEquals(128, solution1.tupleSameProduct(new int[]{1, 2, 3, 4, 6, 8, 12, 24}));
40+
}
41+
42+
}

0 commit comments

Comments
 (0)