design-parking-system.dart (978B)
1 //You are given the number of big medium and small parking spaces 2 //in a given parking system. From here you will add cars 3 //of certain sizes if there are enough spots for them and return 4 //if there are not enough spots return false. 5 //Time: 348ms Beats: 90.91% 6 //Memory: 176MB Beats: 9.9% 7 8 class ParkingSystem { 9 int big = 0; 10 int medium = 0; 11 int small = 0; 12 ParkingSystem(int _big, int _medium, int _small) { 13 big = _big; 14 medium = _medium; 15 small = _small; 16 } 17 18 bool addCar(int carType) { 19 if(carType == 1){ 20 if(big > 0){ 21 big -= 1; 22 return true; 23 } 24 return false; 25 } 26 if(carType == 2){ 27 if(medium > 0){ 28 medium -= 1; 29 return true; 30 } 31 return false; 32 } 33 if(carType == 3){ 34 if(small > 0){ 35 small -= 1; 36 return true; 37 } 38 return false; 39 } 40 return false; 41 } 42 }