Skip to content

Commit f7ca003

Browse files
add a solution for 1010
1 parent a58a295 commit f7ca003

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
return result;
2626
}
2727
}
28+
29+
public static class Solution2 {
30+
/**
31+
* credit: https://leetcode.com/problems/pairs-of-songs-with-total-durations-divisible-by-60/solution/
32+
*/
33+
public int numPairsDivisibleBy60(int[] time) {
34+
int[] remainders = new int[60];
35+
int ans = 0;
36+
for (int t : 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+
return ans;
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
public class _1010Test {
1010
private static _1010.Solution1 solution1;
11+
private static _1010.Solution2 solution2;
1112
private static int[] time;
1213

1314
@BeforeClass
1415
public static void setup() {
1516
solution1 = new _1010.Solution1();
17+
solution2 = new _1010.Solution2();
1618
}
1719

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

2427
@Test
2528
public void test2() {
2629
time = new int[]{60, 60, 60};
2730
assertEquals(3, solution1.numPairsDivisibleBy60(time));
31+
assertEquals(3, solution2.numPairsDivisibleBy60(time));
2832
}
2933

3034
}

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