given a string, we have to split the string in all distinct two and three parts (permutation doesn't matter). for example for:
cat
answer is
ca t
ct a
c at
c a t
for
aaa
answer is
aa a
a a a
how to do that? can you please provide a code in the best possible time complexity?
So i wrote a code for your problem, I wrote this code especially for string containing 3 characters. This code is nothing just "System.out.println" written in different style, if this doesn't suit you please provide me more input i would like it to solve then.` public void checkString(String s) { String strArry[] = s.split("");
if (strArry[0].equalsIgnoreCase(strArry[1])) {
System.out.println(strArry[0] + strArry[1] + " " + strArry[2]);
System.out.println(strArry[0] + " " + strArry[1] + " " + strArry[2]);
} else {
{
System.out.println(strArry[0] + strArry[1] + " " + strArry[2]);
System.out.println(strArry[0] + strArry[2] + " " + strArry[1]);
System.out.println(strArry[0] + " " + strArry[1] + strArry[2]);
System.out.println(strArry[0] + " " + strArry[1] + " " + strArry[2]);
}
}
}`
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.