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

Commitf7ca003

Browse files
add a solution for 1010
1 parenta58a295 commitf7ca003

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

‎src/main/java/com/fishercoder/solutions/_1010.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,23 @@ public int numPairsDivisibleBy60(int[] time) {
2525
returnresult;
2626
}
2727
}
28+
29+
publicstaticclassSolution2 {
30+
/**
31+
* credit: https://leetcode.com/problems/pairs-of-songs-with-total-durations-divisible-by-60/solution/
32+
*/
33+
publicintnumPairsDivisibleBy60(int[]time) {
34+
int[]remainders =newint[60];
35+
intans =0;
36+
for (intt :time) {
37+
if (t %60 ==0) {
38+
ans +=remainders[0];
39+
}else {
40+
ans +=remainders[60 -t %60];
41+
}
42+
remainders[t %60]++;
43+
}
44+
returnans;
45+
}
46+
}
2847
}

‎src/test/java/com/fishercoder/_1010Test.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,27 @@
88

99
publicclass_1010Test {
1010
privatestatic_1010.Solution1solution1;
11+
privatestatic_1010.Solution2solution2;
1112
privatestaticint[]time;
1213

1314
@BeforeClass
1415
publicstaticvoidsetup() {
1516
solution1 =new_1010.Solution1();
17+
solution2 =new_1010.Solution2();
1618
}
1719

1820
@Test
1921
publicvoidtest1() {
2022
time =newint[]{30,20,150,100,40};
2123
assertEquals(3,solution1.numPairsDivisibleBy60(time));
24+
assertEquals(3,solution2.numPairsDivisibleBy60(time));
2225
}
2326

2427
@Test
2528
publicvoidtest2() {
2629
time =newint[]{60,60,60};
2730
assertEquals(3,solution1.numPairsDivisibleBy60(time));
31+
assertEquals(3,solution2.numPairsDivisibleBy60(time));
2832
}
2933

3034
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp