Solved

allStar challenge

Posted on 2016-09-21
1
77 Views
Last Modified: 2016-09-22
Hi,

I am working on below challenge.
http://codingbat.com/prob/p183394
Psedo code:
1. check the array length 0  or 1 then retun same str
2.else return string with first character concatenated with * and then rest of characters argument recursion method

I wrote my code as below and passing all tests
public String allStar(String str) {
  if(str.length()==0||str.length()==1){
    return str;
  }
  else{
  return str.charAt(0)+"*"+allStar(str.substring(1));
  }
}

Open in new window


Any improvements or alternate approaches?      

please advise
0
Comment
Question by:gudii9
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 37

Accepted Solution

by:
zzynx earned 500 total points
ID: 41810216
Not really.

public String allStar(String str) {
  if(str.length()<2){
    return str;
  }
  return str.charAt(0)+"*"+allStar(str.substring(1));
}

Open in new window

0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
The SignAloud Glove is capable of translating American Sign Language signs into text and audio.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Simple Linear Regression
Suggested Courses

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question