Easiest Substring Method In C++ || 100% || 2 line logic
IntuitionThe task requires counting the words that start with a given prefix. We can solve this efficiently by iterating through the words and checking if the p
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
The task requires counting the words that start with a given prefix. We can solve this efficiently by iterating through the words and checking if the prefix matches the start of each word.

# Approach
<!-- Describe your approach to solving the problem. -->
1. Initialize a counter to keep track of the matches.
2. Loop through each word in the list `words`.
3. Extract a substring from the start of the word, with a length equal to the prefix.
4. Compare this substring with the given prefix:
   - If they are equal, increment the counter.
5. After the loop, return the counter as the final result.

# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
  $$O(n \cdot m)$$, where $$n$$ is the number of words and $$m$$ is the length of the prefix.

- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
  $$O(1)$$, since no additional data structures are used.

# Code
```cpp
class Solution {
public:
    int prefixCount(vector<string>& words, string pref) {
        ios::sync_with_stdio(false);
        cin.tie(NULL);

        int cnt = 0;

        for (const string& word : words) {
            if (word.substr(0, pref.size()) == pref) {
                cnt++;
            }
        }

        return cnt;
    }
};

['C++']