Java | Simple counting | 9 lines | Clean code
Approach\n Describe your approach to solving the problem. \nMaintain 3 variables big, small and medium to store the number of available spots of each size. Redu
# Approach\n<!-- Describe your approach to solving the problem. -->\nMaintain 3 variables `big`, `small` and `medium` to store the number of available spots of each size. Reduce the appropriate number based on the input of the `addCar` call. If the capacity reaches `0`, return `false`.\n\n# Complexity\n- Time complexity: $$O(1)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(1)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass ParkingSystem {\n  int big, medium, small;\n\n  public ParkingSystem(int big, int medium, int small) {\n    this.big = big;\n    this.medium = medium;\n    this.small = small;\n  }\n  \n  public boolean addCar(int carType) {\n    switch (carType) {\n      case 1 : return big-- > 0;\n      case 2 : return medium-- > 0;\n      case 3 : return small-- > 0;\n    }\n    return false;\n  }\n}\n```\nIf you like my solution, please upvote it!
['Design', 'Counting', 'Java']