-
Notifications
You must be signed in to change notification settings - Fork 82
/
Copy pathRemove X
49 lines (40 loc) · 787 Bytes
/
Remove X
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
48
49
/*
Given a string, compute recursively a new string where all 'x' chars have been removed.
Input format :
String S
Output format :
Modified String
Constraints :
1 <= |S| <= 10^3
where |S| represents the length of string S.
Sample Input 1 :
xaxb
Sample Output 1:
ab
Sample Input 2 :
abc
Sample Output 2:
abc
Sample Input 3 :
xx
Sample Output 3:
*/
public class solution {
// Return the changed string
public static String removeX(String input){
// Write your code here
if (input.length()==0)
{
return "";
}
String smallOutput=removeX(input.substring(1));
if (input.charAt(0)=='x')
{
return ""+smallOutput;
}
else
{
return input.charAt(0)+smallOutput;
}
}
}