Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

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;
    }
};
 
PREVIOUS NEXT
Tagged: #Count #Prefix #Given #String #solution #leetcode
ADD COMMENT
Topic
Name
3+6 =