Count Prefixes of a Given String

给一个字符串组, 和一个string, 求这个string有几个prefix在这个数组里.

class Solution {
    public int countPrefixes(String[] words, String s) {
        Set<String> set = new HashSet<>();
        for(int i = 1; i <= s.length(); i++){
            set.add(s.substring(0,i));
        }
        int res =0;
        for(String w : words)
            if(set.contains(w))
                res++;
        return res;
    }
}