λ³Έλ¬Έ λ°”λ‘œκ°€κΈ°
πŸƒ algorithm/leetcode

LeetCode 1603 - Design Parking System (Easy)

by HandHand 2023. 4. 24.

 

πŸ’‘ 문제

LeetCode - 1603번

 

🎯 풀이 κ³Όμ •

3μ’…μ˜ μ°¨λŸ‰ (big, medium, small) 을 μˆ˜μš©ν•˜λŠ” μ£Όμ°¨μž₯ μ‹œμŠ€ν…œμ„ κ΅¬ν˜„ν•˜λŠ” λ¬Έμ œμž…λ‹ˆλ‹€.

carType 인덱싱을 νŽΈν•˜κΈ° ν•˜κΈ° μœ„ν•΄ λ°°μ—΄μ˜ 크기λ₯Ό ν•˜λ‚˜ λŠ˜λ €μ„œ μ‚¬μš©ν•©λ‹ˆλ‹€.

 

πŸ‘¨‍πŸ’» μ½”λ“œ

/**
 * @param {number} big
 * @param {number} medium
 * @param {number} small
 */
var ParkingSystem = function(big, medium, small) {
    this.parkingSlots = [0, big, medium, small]
};

/** 
 * @param {number} carType
 * @return {boolean}
 */
ParkingSystem.prototype.addCar = function(carType) {
    if (this.parkingSlots[carType]) {
        this.parkingSlots[carType] -= 1
        return true
    }

    return false
};
λ°˜μ‘ν˜•

πŸ’¬ λŒ“κΈ€