-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patha_392.java
More file actions
31 lines (29 loc) · 823 Bytes
/
a_392.java
File metadata and controls
31 lines (29 loc) · 823 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
package greedy;
/**
* public int IndexOf (char value, int startIndex);
* 从指定位置startIndex返回字符value第一次在字符串中出现的索引值,如果找不到则返回-1
*/
public class a_392 {
/*public boolean isSubsequence(String s, String t) {
int i = 0, j = 0;
while (i < s.length() && j < t.length()) {
char m = s.charAt(i);
char n = t.charAt(j);
if (m == n) {
i++;
}
j++;
}
return i >= s.length();
}*/
public boolean isSubsequence(String s, String t) {
int index = -1;
for (char c : s.toCharArray()) {
index = t.indexOf(c, index+1);
if (index == -1) {
return false;
}
}
return true;
}
}