1010. Pairs of Songs With Total Durations Divisible by 60
给一堆数,问有多少对之和是能被60整除的。
hash。 扫一遍就可以了。注意0和60的edge case
class Solution(object):
def numPairsDivisibleBy60(self, time):
"""
:type time: List[int]
:rtype: int
"""
d = collections.defaultdict(int)
res = 0
for t in time:
remainder = t%60
res += d[(60-remainder) % 60]
d[remainder] += 1
return res