ParkingSystem.java 1.4 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
package com.aen.leetcode;

import java.util.Calendar;
import java.util.HashMap;
import java.util.Map;

/**
 * Title: {@link com.aen.leetcode}
 * Description:
 *
 * @author 谭 tmn
 * @email AbelEthan@126.com
 * @date 20-10-19 下午4:48
 */
public class ParkingSystem {
    private Map<Integer, Integer> map = new HashMap<>();

    private int big;
    private int medium;
    private int small;


    public ParkingSystem(int big, int medium, int small) {
//        map.put(1, big);
//        map.put(2, medium);
//        map.put(3, small);
        this.big = big;
        this.medium = medium;
        this.small = small;
    }

    public boolean addCar(int carType) {
        switch (carType) {
            case 1:
                if (big > 0) {
                    --big;
                    return true;
                }
                break;
            case 2:
                if (medium > 0) {
                    --medium;
                    return true;
                }
                break;
            case 3:
                if (small > 0) {
                    --small;
                    return true;
                }
                break;
        }
        return false;
    }

//    public boolean addCar(int carType) {
//        Integer integer = map.get(carType);
//        if (integer > 0) {
//            map.put(carType, integer-1);
//            return true;
//        }
//        return false;
//    }


}