[Java/C++/Python] Starts With
Explanation\nfor each word w in words list,\ncheck if word w startsWith the string s\n\n\n# Complexity\nTime O(NS)\nSpace O(1)\n\n\nJava\njava\n    public int c
# **Explanation**\nfor each word `w` in `words` list,\ncheck if word `w` `startsWith` the string `s`\n<br>\n\n# **Complexity**\nTime `O(NS)`\nSpace `O(1)`\n<br>\n\n**Java**\n```java\n    public int countPrefixes(String[] words, String s) {\n        int res = 0;\n        for (String w : words)\n            if (s.startsWith(w))\n                res++;\n        return res;\n    }\n```\n\n**C++**\nTime O(NWS)\n```cpp\n    int countPrefixes(vector<string>& words, string s) {\n        int res = 0;\n        for (auto& w : words)\n            res += s.find(w) < 1;\n        return res; \n    }\n```\n\n**C++**\nSuggested by @mzchen\n```cpp\n    int countPrefixes(vector<string>& words, string s) {\n        int res = 0;\n        for (auto& w : words)\n            res += !s.compare(0, w.size(), w);\n        return res;\n    }\n```\n\n**Python**\n```py\n    def countPrefixes(self, words, s):\n        return sum(map(s.startswith, words))\n```\n
['C', 'Python', 'Java']