-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSubSequence.java
More file actions
30 lines (26 loc) · 802 Bytes
/
SubSequence.java
File metadata and controls
30 lines (26 loc) · 802 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
import java.util.*;
class SubSequence
{
static boolean isSubSequence(String str1, String str2, int m, int n)
{
if (m == 0)
return true;
if (n == 0)
return false;
if (str1.charAt(m-1) == str2.charAt(n-1))
return isSubSequence(str1, str2, m-1, n-1);
return isSubSequence(str1, str2, m, n-1);
}
public static void main (String[] args)
{
String str1 = "gksrek";
String str2 = "geeksforgeeks";
int m = str1.length();
int n = str2.length();
boolean res = isSubSequence(str1, str2, m, n);
if(res)
System.out.println("Yes");
else
System.out.println("No");
}
}