첫번째 코드
해당 ruleKey에 맞는 조건을 만든 후 ruleValue에 해당하면 정답을 더하는 방법으로 정답을 구한다.
class Solution:
def countMatches(self, items: List[List[str]], ruleKey: str, ruleValue: str) -> int:
answer = 0
if ruleKey == 'type':
for i in items:
if i[0] == ruleValue:
answer += 1
elif ruleKey == 'color':
for i in items:
if i[1] == ruleValue:
answer += 1
elif ruleKey == 'name':
for i in items:
if i[2] == ruleValue:
answer += 1
return answer
통과
링크
https://github.com/ornni/leetcode/tree/main/1773-count-items-matching-a-rule
leetcode/1773-count-items-matching-a-rule at main · ornni/leetcode
Collection of LeetCode questions to ace the coding interview! - Created using [LeetHub v3](https://github.com/raphaelheinz/LeetHub-3.0) - ornni/leetcode
github.com
'코딩 테스트 > leetcode' 카테고리의 다른 글
Find Words Containing Character (0) | 2024.06.21 |
---|---|
Count Negative Numbers in a Sorted Matrix (0) | 2024.06.20 |
Find The Original Array of Prefix Xor (0) | 2024.06.18 |
Minimum Number of Moves to Seat Everyone (0) | 2024.06.17 |
Range Sum of BST (0) | 2024.06.14 |