8000 :sparkles: Added solution to 1010 · reverse/awesome-golang-leetcode@59518b8 · GitHub
[go: up one dir, main page]

Skip to content

Commit 59518b8

Browse files
author
Sathish Babu
committed
✨ Added solution to 1010
1 parent f2b7626 commit 59518b8

File tree

3 files changed

+34
-9
lines changed

3 files changed

+34
-9
lines changed

src/1010.Pairs-of-Songs-With-Total-Durations-Divisible-by-60/README.md

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,27 @@
55
66
## Description
77

8+
In a list of songs, the i-th song has a duration of time[i] seconds.
9+
10+
Return the number of pairs of songs for which their total duration in seconds is divisible by 60. Formally, we want the number of indices i, j such that i < j with (time[i] + time[j]) % 60 == 0.
11+
12+
**Example 1:**
13+
14+
```
15+
Input: [30,20,150,100,40]
16+
Output: 3
17+
Explanation: Three pairs have a total duration divisible by 60:
18+
(time[0] = 30, time[2] = 150): total duration 180
19+
(time[1] = 20, time[3] = 100): total duration 120
20+
(time[1] = 20, time[4] = 40): total duration 60
21+
```
22+
823
**Example 1:**
924

1025
```
11-
Input: a = "11", b = "1"
12-
Output: "100"
26+
Input: [60,60,60]
27+
Output: 3
28+
Explanation: All three pairs have a total duration of 120, which is divisible by 60.
1329
```
1430

1531
## 题意
Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
package Solution
22

3-
func Solution(x bool) bool {
4-
return x
3+
func Solution(time []int) int {
4+
ans, hash := 0, make([]int, 60)
5+
for _, t := range time {
6+
v := t % 60
7+
if v == 0 {
8+
ans += hash[0]
9+
} else {
10+
ans += hash[60-v]
11+
}
12+
hash[v]++
13+
}
14+
return ans
515
}

src/1010.Pairs-of-Songs-With-Total-Durations-Divisible-by-60/Solution_test.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,11 @@ func TestSolution(t *testing.T) {
1010
// 测试用例
1111
cases := []struct {
1212
name string
13-
inputs bool
14- 74F3
expect bool
13+
inputs []int
14+
expect int
1515
}{
16-
{"TestCase", true, true},
17-
{"TestCase", true, true},
18-
{"TestCase", false, false},
16+
{"TestCase", []int{30, 20, 150, 100, 40}, 3},
17+
{"TestCase", []int{60, 60, 60}, 3},
1918
}
2019

2120
// 开始测试

0 commit comments

Comments
 (0)
0