【python】Leetcode每日一题-设计停车系统
发布日期:2021-05-11 06:28:16 浏览次数:8 分类:博客文章

本文共 2036 字,大约阅读时间需要 6 分钟。

���python���Leetcode������������-������������������

������������������

������������������������������������������������������������������������������������������������������������������������������������������������������������������

������������ ParkingSystem ������

ParkingSystem(int big, int medium, int small) ��������� ParkingSystem ���������������������������������������������������������bool addCar(int carType) ��������������� carType ��������������������� carType ��������������������������������������������������� 1��� 2 ��� 3 ������������������������������ carType ��������������������������������������������������������������� false ��������������������������������������� true ���

������1���

���������["ParkingSystem", "addCar", "addCar", "addCar", "addCar"][[1, 1, 0], [1], [2], [3], [1]]���������[null, true, true, false, false]���������ParkingSystem parkingSystem = new ParkingSystem(1, 1, 0);parkingSystem.addCar(1); // ������ true ������������ 1 ������������������parkingSystem.addCar(2); // ������ true ������������ 1 ������������������parkingSystem.addCar(3); // ������ false ������������������������������parkingSystem.addCar(1); // ������ false ������������������������������������������������������������������������

���������

0 <= big, medium, small <= 1000carType ��������� 1��� 2 ��� 3��������������� addCar ������ 1000 ���

������������

  • ���������������

    AC���������

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        """        if(self.big > 0 and carType == 1):            self.big -= 1            return True        elif(self.medium > 0 and carType == 2):            self.medium -= 1            return True        elif(self.small > 0 and carType == 3):            self.small -= 1            return True        return False
上一篇:【python】Leetcode每日一题-逆波兰表达式求值
下一篇:【python】Leetcode每日一题-反转链表 II

发表评论

最新留言

网站不错 人气很旺了 加油
[***.192.178.218]2025年04月11日 01时38分50秒