当前位置: 代码迷 >> 综合 >> Leetcode 1773. Count Items Matching a Rule
  详细解决方案

Leetcode 1773. Count Items Matching a Rule

热度:43   发布时间:2023-12-12 21:05:42.0

文章作者:Tyan
博客:noahsnail.com  |  CSDN  |  简书

1. Description

Count Items Matching a Rule

2. Solution

**解析:**根据对应的索引比较对应的值即可。

  • Version 1
class Solution:def countMatches(self, items: List[List[str]], ruleKey: str, ruleValue: str) -> int:index = 0if ruleKey == 'color':index = 1elif ruleKey == 'name':index = 2count = 0for item in items:if item[index] == ruleValue:count += 1return count

Reference

  1. https://leetcode.com/problems/count-items-matching-a-rule/
  相关解决方案