1899. Count Items Matching a Rule
My accepted Python solution to LeetCode problem 1899, Count Items Matching a Rule, running in 0ms.
- Difficulty: Easy
- Python
- Runtime 0ms
- Memory 22.4MB
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
Python
Accepted on LeetCode — runtime 0ms, memory 22.4MB, accepted 2025-12-29.
class Solution:
def countMatches(self, items: List[List[str]], ruleKey: str, ruleValue: str) -> int:
# Map ruleKey to index: type=0, color=1, name=2
# Time: O(n), Space: O(1)
key_map = {"type": 0, "color": 1, "name": 2}
idx = key_map[ruleKey]
return sum(1 for item in items if item[idx] == ruleValue)