← 返回 apple 的题目列表Vehicle Information System API Implementation
类型:online_judge
Implement a vehicle information system with two APIs: add and get.
add(color, model, car_type): None: Add a vehicle with the specified color color, model model, and car type car_type to the system.
get(color: str = None, model: str = None, car_type: str = None) -> List[Dict[str, str]]: Search and return all vehicle information that matches the specified color, model, and car type. Parameters can be null, representing a match for any value.
Vehicle information can be stored using a Trie Tree or a three-layer hashmap.
Please provide a solution and give test cases.
Example input:
add('red', 'BMW', 'SUV')
add('blue', 'Tesla', 'Sedan')
add('red', 'Audi', 'Coupe')
get('red')
get('blue', 'Tesla')
Example output:
[{'color': 'red', 'model': 'BMW', 'car_type': 'SUV'}, {'color': 'red', 'model': 'Audi', 'car_type': 'Coupe'}]
[{'color': 'blue', 'model': 'Tesla', 'car_type': 'Sedan'}]
Example
Input
add('red', 'BMW', 'SUV')
add('blue', 'Tesla', 'Sedan')
add('red', 'Audi', 'Coupe')
get('red')
get('blue', 'Tesla')