Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fpdjsns/5d8a60694f68f51a2afd25796fe50c2e to your computer and use it in GitHub Desktop.
Save fpdjsns/5d8a60694f68f51a2afd25796fe50c2e to your computer and use it in GitHub Desktop.
[leetcode] 1013. Pairs of Songs With Total Durations Divisible by 60 : https://leetcode.com/problems/pairs-of-songs-with-total-durations-divisible-by-60/
class Solution {
public:
int numPairsDivisibleBy60(vector<int>& time) {
map<int, int> m;
int answer = 0;
for(int i=0;i<time.size();i++){
int rest = time[i] % 60;
m[rest]++;
}
for(map<int,int>::iterator it = m.begin(); it != m.end(); it++){
pair<int,int> A = *it;
pair<int,int> B = {60 - A.first, m[60 - A.first]};
cout<<A.first <<" "<<A.second<<endl;
if(A.second == 0) continue;
if(A.first == B.first || A.first == 0)
answer += A.second * (A.second - 1) / 2;
else
answer += A.second * B.second;
m[B.first] = 0;
}
return answer;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment