add: 230507-CN

This commit is contained in:
Eatswap 2023-05-07 00:28:41 +08:00
parent 062ec6091a
commit 6ee1746ac6
Signed by: Eatswap
GPG Key ID: BE661106A1F3FA0B
1 changed files with 22 additions and 0 deletions

22
cpp/2305/LC230507CN.cpp Normal file
View File

@ -0,0 +1,22 @@
#include <vector>
/**
* 1010. Pairs of Songs With Total Durations Divisible by 60
*
* You are given a list of songs where the ith song has a duration of time[i] seconds.
* 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.
*/
class LC230507CN {
public:
static int numPairsDivisibleBy60(const std::vector<int>&) noexcept;
};
int LC230507CN::numPairsDivisibleBy60(const std::vector<int>& time) noexcept {
int cnt[60]{}, ret = 0;
for (int i : time) {
ret += cnt[(60 - i % 60) % 60];
++cnt[i % 60];
}
return ret;
}