-
Notifications
You must be signed in to change notification settings - Fork 0
/
792.number-of-matching-subsequences.java
44 lines (36 loc) · 1.18 KB
/
792.number-of-matching-subsequences.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
class Solution {
public int numMatchingSubseq(String s, String[] words) {
List[] map = new ArrayList[26];
for(int i=0;i<s.length();i++){
int ind = s.charAt(i)-'a';
if(map[ind] == null)
map[ind] = new ArrayList<Integer>();
map[ind].add(i);
}
int res = 0;
for(String w: words){
int currind = -1;
boolean found = false;
for(int i=0;i<w.length();i++){
int ind = w.charAt(i)-'a';
if(map[ind] == null){
found = false;
break;
}
for(int j=0;j< map[ind].size();j++){
if((Integer)map[ind].get(j) > currind){
currind = (Integer)map[ind].get(j);
found = true;
break;
}else
found = false;
}
if(!found)
break;
}
if(found)
res++;
}
return res;
}
}