gudii9
asked on
pairstar challenge
Hi,
I am working on below challenge.
http://codingbat.com/prob/p158175
Psedo code:
1. check the array length 0 or 1 then retun same str
2.else return string with * in between for repeated pair of characters
I wrote my code as below and not passing all tests
Any improvements or alternate approaches?
please advise
I am working on below challenge.
http://codingbat.com/prob/p158175
Psedo code:
1. check the array length 0 or 1 then retun same str
2.else return string with * in between for repeated pair of characters
I wrote my code as below and not passing all tests
public String pairStar(String str) {
if(str.length()==0||str.length()==1){
return str;
}
else{
return str.charAt(0)+"*"+pairStar(str.substring(1));
}
}
Expected Run
pairStar("hello") → "hel*lo" "h*e*l*l*o" X
pairStar("xxyy") → "x*xy*y" "x*x*y*y" X
pairStar("aaaa") → "a*a*a*a" "a*a*a*a" OK
pairStar("aaab") → "a*a*ab" "a*a*a*b" X
pairStar("aa") → "a*a" "a*a" OK
pairStar("a") → "a" "a" OK
pairStar("") → "" "" OK
pairStar("noadjacent") → "noadjacent" "n*o*a*d*j*a*c*e*n*t" X
pairStar("abba") → "ab*ba" "a*b*b*a" X
pairStar("abbba") → "ab*b*ba" "a*b*b*b*a" X
other tests
Any improvements or alternate approaches?
please advise
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Open in new window
above passed all tests. any improvements or alternate approaches?