-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1010.py
More file actions
23 lines (19 loc) · 710 Bytes
/
1010.py
File metadata and controls
23 lines (19 loc) · 710 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
class Solution:
def numPairsDivisibleBy60(self, time: List[int]) -> int:
mem = {}
for i, dur in enumerate(time):
key = 60 - (dur % 60) if dur % 60 != 0 else 0
r = mem.get(key, [])
r.append(i)
mem[key] = r
used = set()
pairs = 0
for n in range(len(time)):
r = mem.get(time[n] % 60, [])
if time[n] % 30 != 0 and n not in used:
pairs += len(r)
used.update(r)
if time[n] % 30 == 0 and n not in used:
used.update(r)
pairs += sum(range(1, len(r)))
return pairs