ragavenderan
BAN USERpublic ArrayList getCombinations(String str) {
ArrayList<String> a = new ArrayList<String>();
// System.out.println(a.size());
// a.add("xx");
for ( int i =0 ; i < str.length();i++) {
int k=a.size();
for ( int j=0;j<k;j++)
{
System.out.println(a.get(j)+str.charAt(i));
a.add(a.get(j)+str.charAt(i));
}
a.add(str.charAt(i)+"");
// System.out.println(a.get(0));
}
return a;
}
This should work
public void getCombinations(String str) {
System.out.println(str.length());
for ( int i =0 ; i < str.length();i++) {
for ( int j=i+1;j<=str.length();j++) {
System.out.println(str.substring(i,j));
}
}
}
This is working for me..any thoughts?
@shondik
- ragavenderan July 04, 2012Can you please elaborate your answer.
Because you have told different phone numbers will have same leaf.. how is it possible? we can have linked list at the leaf nodes. Whenever a new phone number is being inserted & the leaf node is already having pointer to some other phone number, we will chain this phone number[create a new node in the linked list & insert its pointer there].? i am not clear with this..
suppose phone number is 9840404040 then 44 , 04, 84 etc all shud give this number..
it would be great if u can explain it with an example.