Hitung awalan solusi string yang diberikan leetcode

class Solution {
public:
    int countPrefixes(vector<string>& words, string s) {
        map<string,int> mp;
        int n = s.size();
        string temp;
        for(int i=0;i<n;i++){
            temp += s[i];
            mp[temp]++;
        }
        int n1 = words.size();
        int count = 0;
        for(int i=0;i<n1;i++){
            if(mp.find(words[i])!=mp.end())
                count++;
        }
        return count;
    }
};
Expensive Earthworm