-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSkipStr.java
More file actions
29 lines (22 loc) · 814 Bytes
/
SkipStr.java
File metadata and controls
29 lines (22 loc) · 814 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
package RecursionBacktracking.level2;
public class SkipStr {
static String skip(String orgStr, String remStr) {
String resStr = new String();
return skipHelper(orgStr, remStr, resStr);
}
static String skipHelper(String orgStr, String remStr, String resStr) {
if (orgStr.isEmpty()) {
return resStr;
}
if (orgStr.startsWith(remStr)) {
resStr = resStr + orgStr.substring(remStr.length());
return skipHelper(orgStr.substring(remStr.length()), remStr, resStr);
}
return skipHelper(orgStr.substring(remStr.length()), remStr, resStr);
}
public static void main(String[] args) {
String orgStr = "abcedfg";
String remStr = "ced";
System.out.println(skip(orgStr, remStr));
}
}