class Solution:
def numPairsDivisibleBy60(self, time: 'List[int]') -> int:
sums = 0
s = {}
n = len(time)
if n>=20:
targets = []
for i in range(1,19):
targets.append(60*i)
for i in range(len(time)):
cur = time[i]
for tar in targets:
cop = tar - cur
if cop < 0:
continue
elif cop > 500:
break
elif cop in s.keys():
sums += s[cop]
if cur in s.keys():
s.update({cur:s[cur]+1})
else:
s.update({cur:1})
else:
for i in range(len(time)):
for j in range(i+1,len(time)):
if (time[i]+time[j])%60==0:
sums+=1
return sums

下面这个是简写:

 class Solution:
def numPairsDivisibleBy60(self, time: 'List[int]') -> int:
c = collections.Counter()
res = 0
for t in time:
res += c[-t % 60]
c[t % 60] += 1
return res

leetcode1010的更多相关文章

  1. [Swift]LeetCode1010. 总持续时间可被 60 整除的歌曲 | Pairs of Songs With Total Durations Divisible by 60

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

随机推荐

  1. Temporary ASP.NET Files\root 空间增长太快

    估计是虚拟目录有新的文件,造成项目重新被编译要么把新文件放到另一个目录,要么使用web application而不是web project

  2. [蓝桥杯]ALGO-90.算法训练_出现次数最多的整数

    问题描述 编写一个程序,读入一组整数,这组整数是按照从小到大的顺序排列的,它们的个数N也是由用户输入的,最多不会超过20.然后程序将对这个数组进行统计,把出现次数最多的那个数组元素值打印出来.如果有两 ...

  3. C++进阶--多继承

    //########################################################################### /* * 多继承 * * -- 一个类直接派 ...

  4. DB2日志清理

    1.在windows系统中,DB2 日志db2diag.log 在什么地方? 以下是IBM网站上的解答 Question Where is db2diag.log for DB2 V9.5 locat ...

  5. 【ZZ】谈谈持续集成,持续交付,持续部署之间的区别

    谈谈持续集成,持续交付,持续部署之间的区别 http://blog.flow.ci/cicd_difference/ 谈谈持续集成,持续交付,持续部署之间的区别 2016年08月03日 标签:beta ...

  6. SecureCRT & SecureFx 绿色破解版

    租了腾讯云的服务器,是 ubuntu 版的,需要用到 SecureCRT 工具来远程链接,但是连接的只是控制台,只能输入命令操作,如果要下载文件什么的,就很麻烦,这时可以使用 SecureFx 来传输 ...

  7. es6 class函数的用法,及兼容程度

    //es6中 class的新特性:面向对象的方式 class name{ fram(){ var div=document.getElementById("div"); div.s ...

  8. 方法 - 调试Dll方法

    1.exe加载dll 2.Dll属性设置2.1运行exe生成Debug/...exe2.2属性->调试->命令-> 改成 ./Debug/调试Dll.exe ../Debug/调试D ...

  9. logging模块知识点及应用小结

    Logging模块知识点: 一.分为5个级别:debug(),info(),warning(),error(),critical().级别由低到高  1.1最简单的用法: 1.2 如果想把日志写到文件 ...

  10. [UE4]给Widget增加参数,Pre Construct和Construct的区别

    使用Pre Construct事件可以在编辑器中实时显示出选择的背景图片. 如果使用的是“Construct”事件则只能在游戏运行时把图片显示出来.