-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSkipEleStr.java
More file actions
47 lines (39 loc) · 1.36 KB
/
SkipEleStr.java
File metadata and controls
47 lines (39 loc) · 1.36 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
44
45
46
47
package RecursionBacktracking.level1;
public class SkipEleStr {
// static void skipElementStr(String string, char target) {
// String resulString = new String();
// helper(string, target, resulString);
// }
// static void helper(String str, char target, String result) {
// if (str.isEmpty()) {
// System.out.println(result);
// return;
// }
// if (str.charAt(0) != target) {
// result = result + str.charAt(0);
// helper(str.substring(1), target, result);
// } else {
// helper(str.substring(1), target, result);
// }
// }
static String skipElementStr(String string, char target) {
String resulString = new String();
return helper(string, target, resulString);
}
static String helper(String str, char target, String result) {
if (str.isEmpty()) {
// System.out.println(result);
return result;
}
if (str.charAt(0) != target) {
result = result + str.charAt(0);
return helper(str.substring(1), target, result);
}
return helper(str.substring(1), target, result);
}
public static void main(String[] args) {
String str = "abcdefaab";
char target = 'a';
System.out.println( skipElementStr(str, target));
}
}