-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStringManipulate.java
64 lines (50 loc) · 1.05 KB
/
StringManipulate.java
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import java.util.ArrayList;
import java.util.List;
public class StringManipulate {
public static List<String> l = new ArrayList<String>();
public static void checkSubString(String a)
{
for(int i = a.length()-1; i>=0;i--)
{
if(i==a.length()-1)
{
String b = a + "()";
if(!l.contains(b))
{
l.add(b);
}
String f = a.substring(0,i);
String g = a.substring(i);
b = f + "()" + g;
if(!l.contains(b))
{
l.add(b);
}
}
if(a.charAt(i)==')')
{
String f = a.substring(0, i);
String g = a.substring(i, a.length());
String b = f + "()"+g;
if(!l.contains(b))
{
l.add(b);
}
}
}
}
public static void main(String[] args)
{
StringManipulate s = new StringManipulate();
//String a = "(())";
List<String> input = new ArrayList<String>();
input.add("(())");
input.add("()()");
for(int j=0;j<input.size();j++)
{
s.checkSubString(input.get(j));
}
for(int j = 0; j<l.size();j++)
System.out.println(l.get(j));
}
}