본문 바로가기
IT/알고리즘

30★★] Leetcode 1010. Pairs of Songs With Total Durations Divisible by 60

by 깻잎쌈 2020. 7. 10.
반응형
 

Pairs of Songs With Total Durations Divisible by 60 - LeetCode

Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.

leetcode.com

#시간초과주의 

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;
    }    
    
};

 

반응형

댓글