Skip to content

Commit 61f6499

Browse files
committed
add solution of 1773
1773. Count Items Matching a Rule - https://leetcode.com/problems/count-items-matching-a-rule/
1 parent 74bad1c commit 61f6499

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
"""
2+
1773. Count Items Matching a Rule
3+
- https://leetcode.com/problems/count-items-matching-a-rule/
4+
"""
5+
6+
# Method 1
7+
# Sequential
8+
9+
class Solution:
10+
def countMatches(self, items: List[List[str]], ruleKey: str, ruleValue: str) -> int:
11+
keyDict = {
12+
"type" : 0,
13+
"color" : 1,
14+
"name" : 2
15+
}
16+
ruleKeyValue = keyDict[ruleKey]
17+
count = 0
18+
for item in items:
19+
if item[ruleKeyValue] == ruleValue:
20+
count += 1
21+
return count

0 commit comments

Comments
 (0)