1013. Pairs of Songs With Total Durations Divisible by 60总持续时间可被 60 整除的歌曲

网址:https://leetcode.com/problems/pairs-of-songs-with-total-durations-divisible-by-60/submissions/

参考:https://blog.csdn.net/Sea_muxixi/article/details/88649191

  1. 直接双层for循环必定tle
  2. 在一轮遍历中将t取余存入map中
  3. 之后只需要遍历一个大小为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;
}
};

1013. Pairs of Songs With Total Durations Divisible by 60总持续时间可被 60 整除的歌曲

上一篇:【LeetCode】1013. Pairs of Songs With Total Durations Divisible by 60 解题报告(Python)


下一篇:Canvas基础讲义