Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 0 additions & 30 deletions src/ParkingSystem1603.java

This file was deleted.

25 changes: 25 additions & 0 deletions src/main/java/com/leetcode/easy/DesignParkingSystem1603.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Tags: Design, Simulation, Counting
package com.leetcode.easy;

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

public class DesignParkingSystem1603 {
private final Map<Integer, Integer> spaces = new HashMap<>();

public DesignParkingSystem1603(int big, int medium, int small) {
this.spaces.put(1, big);
this.spaces.put(2, medium);
this.spaces.put(3, small);
}

public boolean addCar(int carType) {
int remaining = this.spaces.get(carType);
if (remaining == 0) {
return false;
}
this.spaces.put(carType, remaining - 1);
return true;

}
}
23 changes: 23 additions & 0 deletions src/test/java/com/leetcode/easy/DesignParkingSystem1603Test.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.leetcode.easy;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.*;

public class DesignParkingSystem1603Test {

@Test
void testAddCar_Example1() {
DesignParkingSystem1603 parkingSystem = new DesignParkingSystem1603(1, 1, 0);

boolean result1 = parkingSystem.addCar(1); // big car - true
boolean result2 = parkingSystem.addCar(2); // medium car - true
boolean result3 = parkingSystem.addCar(3); // small car - false (no slots)
boolean result4 = parkingSystem.addCar(1); // big car - false (already occupied)

assertTrue(result1);
assertTrue(result2);
assertFalse(result3);
assertFalse(result4);
}
}
Loading