Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb63d865

Browse files
add 1726
1 parent339526f commitb63d865

File tree

3 files changed

+65
-0
lines changed

3 files changed

+65
-0
lines changed

‎README.md

Lines changed: 1 addition & 0 deletions
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|
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
packagecom.fishercoder.solutions;
2+
3+
importjava.util.HashMap;
4+
importjava.util.Map;
5+
6+
publicclass_1726 {
7+
publicstaticclassSolution1 {
8+
publicinttupleSameProduct(int[]nums) {
9+
Map<Integer,Integer>map =newHashMap<>();
10+
intcount =0;
11+
for (inti =0;i <nums.length -1;i++) {
12+
for (intj =i +1;j <nums.length;j++) {
13+
intproduct =nums[i] *nums[j];
14+
count +=8 *map.getOrDefault(product,0);
15+
map.put(product,map.getOrDefault(product,0) +1);
16+
}
17+
}
18+
returncount;
19+
}
20+
21+
}
22+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
packagecom.fishercoder;
2+
3+
importcom.fishercoder.solutions._1726;
4+
importorg.junit.BeforeClass;
5+
importorg.junit.Test;
6+
7+
importstaticorg.junit.Assert.assertEquals;
8+
9+
publicclass_1726Test {
10+
privatestatic_1726.Solution1solution1;
11+
12+
@BeforeClass
13+
publicstaticvoidsetup() {
14+
solution1 =new_1726.Solution1();
15+
}
16+
17+
@Test
18+
publicvoidtest1() {
19+
assertEquals(8,solution1.tupleSameProduct(newint[]{2,3,4,6}));
20+
}
21+
22+
@Test
23+
publicvoidtest2() {
24+
assertEquals(16,solution1.tupleSameProduct(newint[]{1,2,4,5,10}));
25+
}
26+
27+
@Test
28+
publicvoidtest3() {
29+
assertEquals(40,solution1.tupleSameProduct(newint[]{2,3,4,6,8,12}));
30+
}
31+
32+
@Test
33+
publicvoidtest4() {
34+
assertEquals(0,solution1.tupleSameProduct(newint[]{2,3,5,7}));
35+
}
36+
37+
@Test
38+
publicvoidtest5() {
39+
assertEquals(128,solution1.tupleSameProduct(newint[]{1,2,3,4,6,8,12,24}));
40+
}
41+
42+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp