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 ...
随机推荐
- ALGO-43_蓝桥杯_算法训练_A+B Problem
问题描述 输入A,B. 输出A+B. 输入格式 输入包含两个整数A,B,用一个空格分隔. 输出格式 输出一个整数,表示A+B的值. 样例输入 样例输出 数据规模和约定 -,,,<=A,B< ...
- 使用jquery.mCustomScrollbar自定义滚动条(4)live使用,向未来元素添加滚动条,不实用,了解一下
.div_box元素是本来没有的,在滚动条初始化的时候方法是加在$('.content .div_box').mCustomScrollbar()上面,参数live:on; 点击按钮的时候,进行con ...
- 峰Redis学习(5)Redis 数据结构(Set的操作)
第五节:Redis 数据结构之Set 类型 存储Set,这里的Set是无序的: 和List类型不同的是,Set集合中不允许出现重复的元素 Set可包含的最大元素数量是4294967295 存储 ...
- sudo 命令报错的解决方法
尝试着用终端打开Mac的安全权限(sudo spctl --master-disable),却显示以下提示,望高手解答. sudo: /etc/sudoers is world writablesud ...
- spring笔记-@Primary注解
1.问题 当一个接口有2个不同实现时,使用@Autowired注解时会报org.springframework.beans.factory.NoUniqueBeanDefinitionExceptio ...
- script中type属性讲解
js的代码是由type决定的: <script type='javascript'> 默认的 <script type="text/html" > 就是 ...
- Zabbix agentd 命令
#zabbix_agentd -p 查看zabbix所有的内置监控项 [root@nod01 zabbix_agentd.d]# zabbix_agentd -pagent.hostname [s|Z ...
- es中的一些知识点记录
1. forcemerge接口 强制段合并,设置为1时,是期望最终只有1个索引段.但实际情况是,合并的结果是段的总数会减少,但仍大于1,可以多次执行强制合并的命令. 设置的的目标值越小.合并消耗的时间 ...
- Replicating a 2D dynamic array
转自:https://forums.unrealengine.com/community/community-content-tools-and-tutorials/105-saxonrahs-tut ...
- 使用Solrj 获取语句分词结果的代码
import java.util.ArrayList; import java.util.Iterator; import java.util.List; import org.apache.log4 ...