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

Commit 74ac796

Browse files
author
openset
committed
Add: Pairs of Songs With Total Durations Divisible by 60
1 parent 81ec23f commit 74ac796

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package pairs_of_songs_with_total_durations_divisible_by_60
2+
3+
func numPairsDivisibleBy60(time []int) int {
4+
ans, m := 0, [60]int{}
5+
for _, t := range time {
6+
ans += m[(60-t%60)%60]
7+
m[t%60]++
8+
}
9+
return ans
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package pairs_of_songs_with_total_durations_divisible_by_60
2+
3+
import "testing"
4+
5+
type caseType struct {
6+
input []int
7+
expected int
8+
}
9+
10+
func TestNumPairsDivisibleBy60(t *testing.T) {
11+
tests := [...]caseType{
12+
{
13+
input: []int{30, 20, 150, 100, 40},
14+
expected: 3,
15+
},
16+
{
17+
input: []int{60, 60, 60},
18+
expected: 3,
19+
},
20+
}
21+
for _, tc := range tests {
22+
output := numPairsDivisibleBy60(tc.input)
23+
if output != tc.expected {
24+
t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected)
25+
}
26+
}
27+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /