Preview:
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;
    }
};
downloadDownload PNG downloadDownload JPEG downloadDownload SVG

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter