Python
class ParkingSystem(object):
def __init__(self, big, medium, small):
"""
:type big: int
:type medium: int
:type small: int
"""
self.big = big
self.medium = medium
self.small = small
def addCar(self, carType):
"""
:type carType: int
:rtype: bool
"""
a = True
b = False
if carType == 1:
if self.big >= 1:
self.big = self.big -1
return a
else:
return b
elif carType == 2:
if self.medium >= 1:
self.medium = self.medium -1
return a
else:
return b
elif carType == 3:
if self.small >= 1:
self.small = self.small -1
return a
else:
return b
else:
return
class ParkingSystem(object):
def __init__(self, big, medium, small):
self.park = [0, big, medium, small]
def addCar(self, carType):
if self.park[carType] == 0:
return False
self.park[carType] -= 1
return True
作者:fuxuemingzhu
链接:https://leetcode-cn.com/problems/design-parking-system/solution/ru-he-she-ji-ting-che-xi-tong-fu-tuo-zha-4363/
来源:力扣(LeetCode)
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
C++
class ParkingSystem {
public:
int b, m, s;
ParkingSystem(int big, int medium, int small): b(big), m(medium), s(small) {}
bool addCar(int carType) {
if (carType == 1) {
if (b > 0) {
b--;
return true;
}
} else if (carType == 2) {
if (m > 0) {
m--;
return true;
}
} else if (carType == 3) {
if (s > 0) {
s--;
return true;
}
}
return false;
}
};
作者:LeetCode-Solution
链接:https://leetcode-cn.com/problems/design-parking-system/solution/she-ji-ting-che-xi-tong-by-leetcode-solu-p52h/
来源:力扣(LeetCode)
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
class ParkingSystem {
public:
ParkingSystem(int big, int medium, int small) {
park = {0, big, medium, small};
}
bool addCar(int carType) {
return park[carType] -- > 0;
}
private:
vector<int> park;
};
作者:fuxuemingzhu
链接:https://leetcode-cn.com/problems/design-parking-system/solution/ru-he-she-ji-ting-che-xi-tong-fu-tuo-zha-4363/
来源:力扣(LeetCode)
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
2021.03.19——力扣每日一题_1603.设计停车系统