Advertisement
Guest User

Bonus Serie U08 Ricardo Heinzmann

a guest
Nov 18th, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.08 KB | None | 0 0
  1. public class EnthaltenMitAbstand {
  2.     public static void main(String[] args) {}
  3.  
  4.     public static boolean enthalten(String s, String t, int abstand) {
  5.         if (t.isEmpty()) {
  6.             return true;
  7.         }
  8.         for (int i = 0; i < s.length(); i++) {
  9.                 if(recursion(s.substring(i), t, abstand)==true){return true;}    
  10.         }
  11.         return false;
  12.     }
  13.     public static boolean recursion(String s, String t, int abstand) {
  14.         if(s.length() > 0){
  15.         String current;
  16.         current = s.substring(0, 1);
  17.         if (t.contains(current)) {
  18.             String substrs;
  19.             String substrt = t.replaceFirst(current, "");
  20.             for (int i = 0; i <= abstand; i++) {
  21.                 if(s.length() >i){
  22.                  substrs = s.substring(i+1);
  23.                  if (true == recursion(substrs, substrt, abstand)) {
  24.                              return true;
  25.                       }
  26.             }
  27.             }
  28.         }
  29.         }
  30.         if (t.isEmpty()) {
  31.             return true;
  32.         }
  33.         return false;
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement