Skip to content

Commit 1c44b97

Browse files
authored
Create 1013-pairs-of-songs-with-total-durations-divisible-by-60.js
1 parent f059f58 commit 1c44b97

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* @param {number[]} time
3+
* @return {number}
4+
*/
5+
const numPairsDivisibleBy60 = function(time) {
6+
const count = new Map();
7+
let n = 0;
8+
for (let t of time) {
9+
// two sum like method
10+
let d = (60 - t % 60) % 60;
11+
if (count.has(d)) { n += count.get(d); }
12+
count.set(t % 60, 1 + (count.get(t % 60) || 0));
13+
}
14+
return n;
15+
};

0 commit comments

Comments
 (0)