1604. Alert Using Same Key-Card Three or More Times in a One Hour Period
Содержание
class Solution:
def alertNames(self, keyName: List[str], keyTime: List[str]) -> List[str]:
d = defaultdict(list)
for name, t in zip(keyName, keyTime):
t = int(t[:2]) * 60 + int(t[3:])
d[name].append(t)
res = []
for name, ts in d.items():
if (n := len(ts)) > 2:
ts.sort()
for i in range(n - 2):
if ts[i + 2] - ts[i] <= 60:
res.append(name)
break
res.sort()
return res