Answers for "Count Prefix of a Given String solution leetcode"

C++
1

Count Prefix of a Given String solution 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;
    }
};
Posted by: Guest on May-04-2022

Code answers related to "Count Prefix of a Given String solution leetcode"

Browse Popular Code Answers by Language