-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLC2825.java
More file actions
43 lines (34 loc) · 1.07 KB
/
LC2825.java
File metadata and controls
43 lines (34 loc) · 1.07 KB
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
41
42
43
/*
* LC2825
*/
import java.util.*;
public class LC2825 {
public static boolean canMakeSubsequence(String str1, String str2) {
int idx1 = 0, idx2 = 0;
int n = str1.length();
int m = str2.length();
if (m > n) {
return false;
}
while (idx2 < m && idx1 < n) {
if ((str1.charAt(idx1) == str2.charAt(idx2)) || (str1.charAt(idx1) == str2.charAt(idx2) - 1)
|| (str1.charAt(idx1) == 'z' && str2.charAt(idx2) == 'a')) {
idx2++;
}
idx1++;
}
return idx2 == m;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter The String-1 Here : ");
String str1 = sc.nextLine();
System.out.println();
System.out.print("Enter The String-2 Here : ");
String str2 = sc.nextLine();
System.out.println();
boolean ans = canMakeSubsequence(str1.toLowerCase(), str2.toLowerCase());
System.out.println(ans);
sc.close();
}
}