-
-
Notifications
You must be signed in to change notification settings - Fork 109
Expand file tree
/
Copy pathSuperReducedString.java
More file actions
32 lines (29 loc) 路 730 Bytes
/
Copy pathSuperReducedString.java
File metadata and controls
32 lines (29 loc) 路 730 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
30
31
32
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
String s=sc.nextLine();
int l=s.length();
System.out.println(check(s,l));
}
public static String check(String s,int l){
if(l==0)
return "Empty String";
char a=s.charAt(0);
char b;
for(int i=1;i<l;i++){
b=s.charAt(i);
if(b==a){
s=s.substring(0,i-1)+s.substring(i+1,l);
l-=2;
return check(s,l);
}
a=b;
}
return s;
}
}