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

Commit078a2ca

Browse files
add Java solution for 2001
1 parent324c6bd commit078a2ca

File tree

3 files changed

+48
-1
lines changed

3 files changed

+48
-1
lines changed

‎README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ _If you like this project, please leave me a star._ ★
88

99
| # | Title | Solutions | Video | Difficulty | Tag
1010
|-----|----------------|---------------|--------|-------------|-------------
11-
|2001|[Number of Pairs of Interchangeable Rectangles](https://leetcode.com/problems/number-of-pairs-of-interchangeable-rectangles/)|[Python3](../master/python3/2001.py)||Medium||
11+
|2001|[Number of Pairs of Interchangeable Rectangles](https://leetcode.com/problems/number-of-pairs-of-interchangeable-rectangles/)|[Python3](../master/python3/2001.py),[Java](../master/src/main/java/com/fishercoder/solutions/_2001.java)||Medium||
1212
|2000|[Reverse Prefix of Word](https://leetcode.com/problems/reverse-prefix-of-word/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_2000.java)||Easy||
1313
|1996|[The Number of Weak Characters in the Game](https://leetcode.com/problems/the-number-of-weak-characters-in-the-game/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1996.java)||Medium||
1414
|1995|[Count Special Quadruplets](https://leetcode.com/problems/count-special-quadruplets/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1995.java)||Easy||
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
packagecom.fishercoder.solutions;
2+
3+
importjava.util.HashMap;
4+
importjava.util.Map;
5+
6+
publicclass_2001 {
7+
publicstaticclassSolution1 {
8+
/**
9+
* credit: https://github.com/fishercoder1534/Leetcode/blob/master/python3/2001.py
10+
*/
11+
publiclonginterchangeableRectangles(int[][]rectangles) {
12+
Map<Double,Integer>map =newHashMap<>();
13+
for (int[]rec :rectangles) {
14+
doubleratio = (double)rec[0] /rec[1];
15+
map.put(ratio,map.getOrDefault(ratio,0) +1);
16+
}
17+
longanswer =0;
18+
for (doubleratio :map.keySet()) {
19+
intcount =map.get(ratio);
20+
answer += (long)count * (count -1) /2;
21+
}
22+
returnanswer;
23+
}
24+
}
25+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
packagecom.fishercoder;
2+
3+
importcom.fishercoder.common.utils.CommonUtils;
4+
importcom.fishercoder.solutions._2001;
5+
importorg.junit.BeforeClass;
6+
importorg.junit.Test;
7+
8+
importstaticorg.junit.Assert.assertEquals;
9+
10+
publicclass_2001Test {
11+
privatestatic_2001.Solution1solution1;
12+
13+
@BeforeClass
14+
publicstaticvoidsetup() {
15+
solution1 =new_2001.Solution1();
16+
}
17+
18+
@Test
19+
publicvoidtest1() {
20+
assertEquals(6,solution1.interchangeableRectangles(CommonUtils.convertLeetCodeIrregularLengths2DArrayInputIntoJavaArray("[4,8],[3,6],[10,20],[15,30]")));
21+
}
22+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp