Count Items Matching a Rule

PHOTO EMBED

Sat Oct 08 2022 04:45:10 GMT+0000 (Coordinated Universal Time)

Saved by @Ranjan_kumar #c++

class Solution {
public:
    int countMatches(vector<vector<string>>& items, string ruleKey, string ruleValue) {
        int n=items.size();
        int p=3;
        int i;
        int c=0;
        if(ruleKey=="type")
        {
            i=0;
            for(int j=0;j<n;j++)
            {
                if(items[j][i]==ruleValue)
                {c++;}
            }
        }
        else if(ruleKey=="color")
        {
            i=1;
            for(int j=0;j<n;j++)
            {
                if(items[j][i]==ruleValue) {c++;}
            }
        }
        else if(ruleKey=="name")
        {
            i=2;
            for(int j=0;j<n;j++)
            {
                if(items[j][i]==ruleValue) {c++;}
            }
        }
        return c;
    }
};
content_copyCOPY

https://leetcode.com/problems/count-items-matching-a-rule/