commit 58ae575e67fd69adda079b167c243ffbdbb54c97 parent 5b581ccb6a702795a33554ca845e2855d9282c1e Author: AndrewLockVI <andrewlaack1@gmail.com> Date: Sun, 28 May 2023 19:31:20 -0500 Completed design parking system using dart Diffstat:
| A | design-parking-system/design-parking-system.dart | | | 42 | ++++++++++++++++++++++++++++++++++++++++++ |
1 file changed, 42 insertions(+), 0 deletions(-)
diff --git a/design-parking-system/design-parking-system.dart b/design-parking-system/design-parking-system.dart @@ -0,0 +1,42 @@ +//You are given the number of big medium and small parking spaces +//in a given parking system. From here you will add cars +//of certain sizes if there are enough spots for them and return +//if there are not enough spots return false. +//Time: 348ms Beats: 90.91% +//Memory: 176MB Beats: 9.9% + +class ParkingSystem { + int big = 0; + int medium = 0; + int small = 0; + ParkingSystem(int _big, int _medium, int _small) { + big = _big; + medium = _medium; + small = _small; + } + + bool addCar(int carType) { + if(carType == 1){ + if(big > 0){ + big -= 1; + return true; + } + return false; + } + if(carType == 2){ + if(medium > 0){ + medium -= 1; + return true; + } + return false; + } + if(carType == 3){ + if(small > 0){ + small -= 1; + return true; + } + return false; + } + return false; + } +}