Number of Strings That Appear as Substrings in Word
给一个parttern数组和一个string, 问有多少这个string的substring在pattern数组里.
class Solution {
public int numOfStrings(String[] patterns, String word) {
Set<String> set = new HashSet<>();
for(int i = 0; i <= word.length(); i++)
{
for(int j = i; j <= word.length(); j++)
{
set.add(word.substring(i,j));
}
}
int res = 0;
for(String p : patterns)
if(set.contains(p))
res++;
return res;
}
}