# 1010. Pairs of Songs With Total Durations Divisible by 60 ###### tags: `Leetcode` `Medium` Link: https://leetcode.com/problems/pairs-of-songs-with-total-durations-divisible-by-60/ ## 思路 $O(N)$ $O(1)$ 很简单的一道题 用一个length = 60的array记录前面每个余数出现的次数(如果用map会变慢) 当一个新的time出现的时候 先取余数 然后看60-余数是否出现过(如果余数是0,则看0有没有出现过) 如果有则count++并记录该余数出现过 如果没有则只记录该余数 ## Code ```java= class Solution { public int numPairsDivisibleBy60(int[] time) { int ans = 0; int[] cnt = new int[60]; for(int t:time){ ans+=cnt[t%60==0?0:60-t%60]; cnt[t%60]++; } return ans; } } ```