leetcode1010
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的更多相关文章
- [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 ...
随机推荐
- 关于Javascript闭包(Closure)
闭包(closure)是Javascript语言的一个难点,也是它的特色,很多高级应用都要依靠闭包实现. 一.变量的作用域 要理解闭包,首先必须理解Javascript特殊的变量作用域. 变量的作用域 ...
- C++进阶--隐式类型转换
//############################################################################ /* 隐式类型转换 * * 类型转换可分为 ...
- windows迁移linux问题集锦
1)‘_wcsicmp’在此作用域中尚未声明 #ifdef WIN32#define _tcsicmp _wcsicmp#else#define _tcsicmp wcsc ...
- centos7 安装 codeblock(rpm)
--------------------- 1.yum -y install epel-release 2.yum clean all && yum makecache 3.yum - ...
- Android开发之点击事件(Button)
Button点击事件 创建项目: 1.Fiel-------->New ------->Android Application Project 2.将Form Widght 文件中的But ...
- [Easyui - Grid]为easyui的datagrid、treegrid增加表头菜单,用于显示或隐藏列
为easyui的datagrid.treegrid增加表头菜单,用于显示或隐藏列 /** * @author 孙宇 * * @requires jQuery,EasyUI * * 为datagrid. ...
- 服务网关zuul之三:zuul统一异常处理
我们详细介绍了Spring Cloud Zuul中自己实现的一些核心过滤器,以及这些过滤器在请求生命周期中的不同作用.我们会发现在这些核心过滤器中并没有实现error阶段的过滤器.那么这些过滤器可以用 ...
- JavaScript for...in 循环
JavaScript for...in 语句循环遍历对象的属性. 语法 for (对象中的变量) { 要执行的代码 } 注释:for...in 循环中的代码块将针对每个属性执行一次. 实例 循环遍历对 ...
- T-SQL 带参数存储过程
创建带参数的存储过程 use StudentManager go if exists(select * from sysobjects where name='usp_ScoreQuery4') dr ...
- echart line 初始化隐藏legend
echart line,当line很多,且各line的取值区间相关非常大时,多条line同时显示,其实是没有太大的可读性的,因此需要在初始化时,把部分不太重要的legend隐藏起来. 具体做法如下: ...