Count Items Matching a Rule LeetCode solution in C++

1
class Solution {
2
public:
3
int countMatches(vector<vector<string>> &items, string ruleKey, string ruleValue) {
4
int i;
5
if (ruleKey == "type") i = 0;
6
if (ruleKey == "color") i = 1;
7
if (ruleKey == "name") i = 2;
8

9
int ans = 0;
10
for (int j = 0; j < items.size(); j++) {
11
if (items[j][i] == ruleValue) ans++;
12
}
13

14
return ans;
15
}
16
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0