-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathisSubs.java
More file actions
32 lines (28 loc) · 775 Bytes
/
isSubs.java
File metadata and controls
32 lines (28 loc) · 775 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
public class isSubs {
public static boolean isSubsequence(String s, String t) {
int sl = s.length();
int tl = t.length();
if (s.isEmpty()) {
return true;
}
if (sl > tl) {
return false;
}
int j = 0;
for (int i = 0; i < tl; i++) {
if (s.charAt(j) == t.charAt(i)) {
j++;
if (j == sl) {
return true;
}
}
}
return false;
}
public static void main(String[] args) {
String a = "abc";
String b = "ahbgdc";
boolean result = isSubsequence(a, b);
System.out.println(result); // Output: true
}
}