Skip to content

Commit

Permalink
哈希解法
Browse files Browse the repository at this point in the history
  • Loading branch information
Azureki committed Mar 18, 2019
1 parent 746e959 commit ceb2309
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions 1013. Pairs of Songs With Total Durations Divisible by 60.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class Solution:
def numPairsDivisibleBy60(self, time: List[int]) -> int:
d = {}
for x in time:
x %= 60
d[x] = d.get(x, 0) + 1
count = 0
for k,v in d.items():
if k in (0, 30):
count += v * (v - 1) // 2
elif k < 30:
count += v * d.get(60 - k, 0)
return count

0 comments on commit ceb2309

Please sign in to comment.