Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit ad59c58

Browse files
2021年03月14日
1 parent a07c800 commit ad59c58

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
class ParkingSystem(object):
2+
3+
def __init__(self, big, medium, small):
4+
"""
5+
:type big: int
6+
:type medium: int
7+
:type small: int
8+
"""
9+
self.space = [0, big, medium, small]
10+
11+
def addCar(self, carType):
12+
"""
13+
:type carType: int
14+
:rtype: bool
15+
"""
16+
if self.space[carType]:
17+
self.space[carType] -= 1
18+
return True
19+
return False
20+
21+
22+
# Your ParkingSystem object will be instantiated and called as such:
23+
# obj = ParkingSystem(big, medium, small)
24+
# param_1 = obj.addCar(carType)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
class Solution(object):
2+
def alertNames(self, keyName, keyTime):
3+
"""
4+
:type keyName: List[str]
5+
:type keyTime: List[str]
6+
:rtype: List[str]
7+
"""
8+
from collections import defaultdict
9+
name2time = defaultdict(list)
10+
11+
res = set()
12+
13+
def timeToMinutes(time):
14+
# convert 10:05 to 605
15+
splitted_time = time.split(":")
16+
return 60 * int(splitted_time[0]) + int(splitted_time[1])
17+
18+
pairs = sorted(zip(keyName, keyTime), key = lambda x: (x[0], x[1]))
19+
20+
for name, time in pairs:
21+
if name not in res:
22+
name2time[name].append(time)
23+
if len(name2time[name]) >= 3 and 0 <= timeToMinutes(time) - timeToMinutes(name2time[name][-3]) <= 60:
24+
res.add(name)
25+
26+
return sorted(list(res))
27+
28+

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /