✅Beats 100% | C++ | Simple & Easy to Understand 💥
Intuition💡My first thought on how to solve this problem was to iterate through each word in the words vector and check if it starts with the given prefix pref.
# Intuition💡
<!-- Describe your first thoughts on how to solve this problem. -->
My first thought on how to solve this problem was to iterate through each word in the words vector and check if it starts with the given prefix pref. I knew that the find method in C++ could be used to check if a string contains a substring, and I suspected that it could also be used to check if a string starts with a certain prefix.

# Approach🚀
<!-- Describe your approach to solving the problem. -->
My approach to solving this problem was to use a simple iterative approach. Here are the steps:
Initialize a counter variable count to 0. 📊
Iterate through each word in the words vector. 🔁
For each word, use the find method to check if the word starts with the given prefix pref. 🔍
If the word starts with the prefix (i.e., find returns 0), increment the count variable. 👍
Finally, return the total count of words that start with the given prefix. 📈

# Complexity🤔

- Time complexity:⏰
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
 O(n⋅m), where n is the number of words and m is the maximum length of a word.

- Space complexity:📦
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
O(1), as we only use a constant amount of space to store the count variable. 

# Code
```cpp []
class Solution {
public:
    int prefixCount(vector<string>& words, string pref) {
        int count = 0;
        for (const auto& word : words) {
            if (word.find(pref) == 0) {
                count++;
            }
        }
        return count;
    }
};
```
['C++']