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

Commit59518b8

Browse files
author
Sathish Babu
committed
✨ Added solution to 1010
1 parentf2b7626 commit59518b8

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-
funcSolution(xbool)bool {
4-
returnx
3+
funcSolution(time []int)int {
4+
ans,hash:=0,make([]int,60)
5+
for_,t:=rangetime {
6+
v:=t%60
7+
ifv==0 {
8+
ans+=hash[0]
9+
}else {
10+
ans+=hash[60-v]
11+
}
12+
hash[v]++
13+
}
14+
returnans
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
namestring
13-
inputsbool
14-
expectbool
13+
inputs[]int
14+
expectint
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)

[8]ページ先頭

©2009-2025 Movatter.jp