- Notifications
You must be signed in to change notification settings - Fork 123
Expand file tree
/
Copy pathSubsequence.java
More file actions
Latest commit
40 lines (34 loc) · 1006 Bytes
/
Copy pathSubsequence.java
File metadata and controls
40 lines (34 loc) · 1006 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
36
37
38
39
40
/**
*
*/
importjava.util.*;
publicclassSubsequence {
publicList<String> subsequences(Stringtarget, String[] dict) {
List<String> res = newArrayList<>();
for (Stringword: dict) {
if (target.length() <= word.length() && isSubsequence(target, word)) {
res.add(word);
}
}
returnres;
}
publicbooleanisSubsequence(Strings, Stringt) {
inti = 0;
intj = 0;
char[] chars = s.toCharArray();
char[] chart = t.toCharArray();
while (i < chars.length && j < chart.length) {
if (chars[i] == chart[j]) {
i++;
j++;
} else {
j++;
}
}
returni == chars.length;
}
publicstaticvoidmain(String[] args) {
Insertablesins = newInsertables();
System.out.println(ins.insertables("google", newString[]{"goooooogle", "ddgoogle", "abcd", "googles"}));
}
}