Skip to content

Commit 23f42d2

Browse files
authored
Create pairs-of-songs-with-total-durations-divisible-by-60.cpp
1 parent 56e1843 commit 23f42d2

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+
// Time: O(n)
2+
// Space: O(1)
3+
4+
class Solution {
5+
public:
6+
int numPairsDivisibleBy60(vector<int>& time) {
7+
int result = 0;
8+
vector<int> counter(60);
9+
for (const auto& t : time) {
10+
result += counter[(60 - t % 60) % 60];
11+
++counter[t % 60];
12+
}
13+
return result;
14+
}
15+
};

0 commit comments

Comments
 (0)