-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnumMatchingSubseq
More file actions
35 lines (27 loc) · 831 Bytes
/
numMatchingSubseq
File metadata and controls
35 lines (27 loc) · 831 Bytes
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
class Solution {
public int numMatchingSubseq(String s, String[] words) {
Map<String,Integer> map = new HashMap<>();
for(String str:words){
map.put(str,map.getOrDefault(str,0)+1);
}
int ans = 0;
char ch[] = s.toCharArray();
for(String str:map.keySet()){
char temp[] = str.toCharArray();
int i = 0;
int j = 0;
while(i<ch.length && j<temp.length){
if(ch[i]==temp[j]){
i++;
j++;
}else{
i++;
}
}
if(j==temp.length){
ans+=map.get(str);
}
}
return ans;
}
}