python-algorithm
Leetcode 1773. Count Items Matching a Rule
무적김두칠
2021. 7. 16. 09:52
1
2
3
4
5
6
7
8
9
10
11
|
class Solution:
def countMatches(self, items: List[List[str]], ruleKey: str, ruleValue: str) -> int:
cnt=0
for i in items:
if ruleKey=='type':
if i[0]==ruleValue:cnt+=1
if ruleKey=='color':
if i[1]==ruleValue:cnt+=1
if ruleKey=='name':
if i[2]==ruleValue:cnt+=1
return cnt
|
cs |
반응형