首页 > 其他 > 详细

1010. Pairs of Songs With Total Durations Divisible by 60

时间:2020-07-08 14:33:53      阅读:73      评论:0      收藏:0      [点我收藏+]

In a list of songs, the i-th song has a duration of time[i] seconds. 

Return the number of pairs of songs for which their total duration in seconds is divisible by 60.  Formally, we want the number of indices ij such that i < j with (time[i] + time[j]) % 60 == 0.

这个是模的two sum问题

class Solution(object):
    def numPairsDivisibleBy60(self, time):
        """
        :type time: List[int]
        :rtype: int
        """
        d = {}
        ans = 0
        for value in time:
            if (60 - (value % 60)) % 60 in d:
                ans += d[(60 - (value % 60)) % 60]
            if (value % 60) in d:
                d[value % 60] += 1
            else:
                d[value % 60] = 1
        return ans

 

1010. Pairs of Songs With Total Durations Divisible by 60

原文:https://www.cnblogs.com/whatyouthink/p/13266508.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!