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 ...
随机推荐
- 关于linux中的system函数
Linux下使用system()函数一定要谨慎 https://blog.csdn.net/senen_wakk/article/details/51496322 system()正确应用 https ...
- 【转】探索 ConcurrentHashMap 高并发性的实现机制
原文链接:https://www.ibm.com/developerworks/cn/java/java-lo-concurrenthashmap/ <探索 ConcurrentHashMap ...
- windows迁移linux问题集锦
1)‘_wcsicmp’在此作用域中尚未声明 #ifdef WIN32#define _tcsicmp _wcsicmp#else#define _tcsicmp wcsc ...
- Hive数据导入导出的几种方式
一,Hive数据导入的几种方式 首先列出讲述下面几种导入方式的数据和hive表. 导入: 本地文件导入到Hive表: Hive表导入到Hive表; HDFS文件导入到Hive表; 创建表的过程中从其他 ...
- PHP程序员的进阶之路
第1阶段:初级PHP程序员 重点:把LNMP搞熟练(核心是安装配置基本操作)目标:能够完成基本的LNMP环境安装,简单配置维护:能够做基本的简单系统的PHP开发:能够在PHP中型系统中支持某个PHP功 ...
- ORM多表操作之创建关联表及添加表记录
创建关联表 关于表关系的几个结论 (1)一旦确立表关系是一对多:建立一对多关系----在多对应的表中创建关联字段. (2)一旦确立表关系是多对多:建立多对多关系----创建第三张关系表----id和两 ...
- [UE4]Replications,复制
关于进程 1.进程:运行中的程序 虚幻4游戏进程的四种网络模式 1.StandAlone:单机模式,不联网 2.Client,网络游戏中的客户端. 3.ListenServer,服务器和一个客户端 4 ...
- Android点赞音效播放
/** * 音效播放 */ private SoundPool mPool; /** * 音效id */ private int voiceID; voiceID = initSoundPool(); ...
- Making a view in a listview invisible android
问题: I have a ListView that's using a custom adapter. I want to dynamically add/remove items from the ...
- 移植vsftpd到arm linux
vsftpd即very secure FTP daemon(非常安全的FTP进程),是一个基于GPL发布的类UNIX类操作系统上运行的服务器的名字(是一种守护进程),可以运行在诸如Linux.BSD. ...