Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Subsequence {
- public static void main(String[] args) {
- Scanner input = new Scanner(System.in);
- String key = input.nextLine();
- String code = input.nextLine();
- if(key.length()>code.length()){
- System.out.println(false);
- }
- else if(key.length()!=0){
- findKey(0, key, code, 0);
- }
- }
- private static void findKey(int index, String key, String code, int codeIndex) {
- StringBuilder sb = new StringBuilder();
- if (key.length() == index && codeIndex < code.length()) {
- System.out.println(true);
- return;
- }
- for (int i = codeIndex; i < code.length(); i++) {
- if (key.charAt(index) == code.charAt(i)) {
- codeIndex = i;
- sb.append(key.charAt(index));
- findKey(index + 1, key, code, codeIndex);
- return;
- }
- }
- System.out.println(false);
- return;
- }
- }
Add Comment
Please, Sign In to add comment