Created
March 17, 2019 10:41
-
-
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/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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