Easy & Simple Solution | C++ | Python
Using Ternary Operator in C++ solution\n### Using Dictionary in Python solution\n###### Time complexity : O(n)\nC++ []\nclass Solution {\npublic:\n    int count
### Using Ternary Operator in C++ solution\n### Using Dictionary in Python solution\n###### Time complexity : $$O(n)$$\n```C++ []\nclass Solution {\npublic:\n    int countMatches(vector<vector<string>>& items, string ruleKey, string ruleValue) {\n        int n = (ruleKey == "type" ? 0 : (ruleKey == "color" ? 1 : 2)), c = 0;\n        for(int i = 0; i < items.size(); i++){\n            if(items[i][n] == ruleValue)\n                c++;\n        }\n        return c;\n    }\n};\n```\n```python []\nclass Solution:\n    def countMatches(self, items: List[List[str]], ruleKey: str, ruleValue: str) -> int:\n        keys = {\'type\': 0, \'color\': 1, \'name\': 2}\n        c = 0\n        index = keys[ruleKey]\n        for i in items:\n            if i[index] == ruleValue:\n                c += 1\n        return c  \n```\n---\n### if you like it -> upvote \n
['C', 'Python', 'C++', 'Python3']