Uriel's Corner

Research Associate @ Harvard University / Research Interests: Computer Vision, Biomedical Image Analysis, Machine Learning
posts - 0, comments - 50, trackbacks - 0, articles - 594
给出小中大三种停车位的数量,每次query一种车型问是否还能停进去,简单模拟


 1 #1603
 2 #Runtime: 115 ms (Beats 52.8%)
 3 #Memory: 14.1 MB (Beats 5.83%)
 4 
 5 class ParkingSystem(object):
 6 
 7     def __init__(self, big, medium, small):
 8         """
 9         :type big: int
10         :type medium: int
11         :type small: int
12         """
13         self.cnt_s = small
14         self.cnt_m = medium
15         self.cnt_b = big
16         
17 
18     def addCar(self, carType):
19         """
20         :type carType: int
21         :rtype: bool
22         """
23         if carType == 1:
24             if self.cnt_b > 0:
25                 self.cnt_b -= 1
26                 return True
27             else:
28                 return False
29         if carType == 2:
30             if self.cnt_m > 0:
31                 self.cnt_m -= 1
32                 return True
33             else:
34                 return False
35         if carType == 3:
36             if self.cnt_s > 0:
37                 self.cnt_s -= 1
38                 return True
39             else:
40                 return False
41         
42 
43 
44 # Your ParkingSystem object will be instantiated and called as such:
45 # obj = ParkingSystem(big, medium, small)
46 # param_1 = obj.addCar(carType)

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   博问   Chat2DB   管理