网址:https://leetcode.com/problems/pairs-of-songs-with-total-durations-divisible-by-60/submissions/
参考:https://blog.csdn.net/Sea_muxixi/article/details/88649191
- 直接双层for循环必定tle
- 在一轮遍历中将t取余存入map中
- 之后只需要遍历一个大小为60的map即可解决问题
class Solution {
public:
int numPairsDivisibleBy60(vector<int>& time) {
map<int,int> m;
int nums = ;
for(int t:time)
m[t%]++;
if(m[])
nums = m[] * (m[]-) / ;
cout << nums << endl;
for(int i=;i<;i++)
{
nums += m[i] * m[-i];
}
if(m[])
nums += m[] * (m[]-) / ;
return nums;
}
};