-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQ21.java
More file actions
40 lines (31 loc) · 911 Bytes
/
Q21.java
File metadata and controls
40 lines (31 loc) · 911 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
33
34
35
36
37
38
39
40
import java.util.ArrayList;
public class Q21 {
public static void main(String[] args) {
ArrayList<String > a = new ArrayList<> ();
parition("aabb" , a , 0);
}
private static void parition(String up, ArrayList<String> a , int z) {
if(z == up.length ()){
System.out.println (a);
return;
}
for (int i = z; i < up.length (); i++) {
String ch = up.substring (z , i+ 1);
if(pallindroxme(ch)){
a.add (ch);
parition (up , a , z + 1 );
a.remove (a.size () - 1);
}
}
}
private static boolean pallindroxme(String up) {
int l = 0;
int r = up.length () - 1;
while(l < r ){
if(up.charAt (l)!= up.charAt (r))return false;
l++;
r--;
}
return true;
}
}