Skip to content

Commit b2035f2

Browse files
committed
Add solution #1010
1 parent d07ac58 commit b2035f2

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@
145145
985|[Sum of Even Numbers After Queries](./0985-sum-of-even-numbers-after-queries.js)|Easy|
146146
989|[Add to Array-Form of Integer](./0989-add-to-array-form-of-integer.js)|Easy|
147147
1009|[Complement of Base 10 Integer](./1009-complement-of-base-10-integer.js)|Easy|
148+
1010|[Pairs of Songs With Total Durations Divisible by 60](./1010-pairs-of-songs-with-total-durations-divisible-by-60.js)|Medium|
148149
1037|[Valid Boomerang](./1037-valid-boomerang.js)|Easy|
149150
1103|[Distribute Candies to People](./1103-distribute-candies-to-people.js)|Easy|
150151
1108|[Defanging an IP Address](./1108-defanging-an-ip-address.js)|Easy|
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* 1010. Pairs of Songs With Total Durations Divisible by 60
3+
* https://leetcode.com/problems/pairs-of-songs-with-total-durations-divisible-by-60/
4+
* Difficulty: Medium
5+
*
6+
* You are given a list of songs where the ith song has a duration of time[i] seconds.
7+
*
8+
* Return the number of pairs of songs for which their total duration in seconds is
9+
* divisible by 60. Formally, we want the number of indices i, j such that i < j with
10+
* (time[i] + time[j]) % 60 == 0.
11+
*/
12+
13+
/**
14+
* @param {number[]} time
15+
* @return {number}
16+
*/
17+
var numPairsDivisibleBy60 = function(time) {
18+
const mods = new Array(60).fill(0);
19+
return time.reduce((sum, t) => {
20+
sum += mods[(60 - t % 60) % 60];
21+
mods[t % 60]++;
22+
return sum;
23+
}, 0);
24+
};

0 commit comments

Comments
 (0)