반응형
#시간초과주의
for문 2번 돌리면 시간초과난다.
앞에 더해서 나머지가 0이 되는 숫자 갯수만큼 pair의 갯수가 늘어난다.
class Solution {
public:
int numPairsDivisibleBy60(vector<int>& time) {
int vis[60] = {0};
int ans = 0;
for(int i = 0;i<time.size();i++){
int k = time[i] %60;
ans += vis[(60-k)%60];
vis[k]++;
}
return ans;
}
};
반응형
'IT > 알고리즘' 카테고리의 다른 글
32] Leetcode 807. Max Increase to Keep City Skyline (0) | 2020.07.12 |
---|---|
31] Leetcode 1512. Number of Good Pairs (0) | 2020.07.12 |
29★] Leetcode 1013. Partition Array Into Three Parts With Equal Sum (0) | 2020.07.07 |
28] Leetcode 1021. Remove Outermost Parentheses (0) | 2020.07.06 |
27] Leetcode 1266. Minimum Time Visiting All Points (0) | 2020.07.06 |
댓글