Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public int romanToInt(String s) {
- HashMap<Character, Integer> map = new HashMap<>();
- map.put('I', 1);
- map.put('V', 5);
- map.put('X', 10);
- map.put('L', 50);
- map.put('C', 100);
- map.put('D', 500);
- map.put('M', 1000);
- int sum = 0;
- for (int i = 0; i < s.length() - 1; i++) {
- if (map.get(s.charAt(i)) >= map.get(s.charAt(i + 1))) {
- sum += map.get(s.charAt(i));
- } else {
- sum -= map.get(s.charAt(i));
- }
- }
- sum += map.get(s.charAt(s.length() - 1));
- return sum;
- }
- class ParkingSystem {
- int[] slots;
- public ParkingSystem(int big, int medium, int small) {
- slots = new int[3];
- slots[0] = big;
- slots[1] = medium;
- slots[2] = small;
- }
- public boolean addCar(int carType) {
- if (slots[carType - 1] > 0) {
- slots[carType - 1] -= 1;
- return true;
- }
- return false;
- }
- }
Add Comment
Please, Sign In to add comment