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
本文介绍了一道算法题目,题目要求从给定的一组数值中找出所有两两组合,其和能被60整除的配对数量。通过使用哈希表的方法,文章提供了一个高效的解决方案,并特别注意了0和60的特殊情况。
409

被折叠的 条评论
为什么被折叠?



