Count Items Matching a Rule LeetCode solution in C++
1class Solution {2public:3int countMatches(vector<vector<string>> &items, string ruleKey, string ruleValue) {4int i;5if (ruleKey == "type") i = 0;6if (ruleKey == "color") i = 1;7if (ruleKey == "name") i = 2;89int ans = 0;10for (int j = 0; j < items.size(); j++) {11if (items[j][i] == ruleValue) ans++;12}1314return ans;15}16};