Avatar of gudii9
gudii9
Flag for United States of America

asked on 

noX challenge

Hi,

I am working on below challenge
http://codingbat.com/prob/p118230

Psedo code:
1. if array length is zero return ""
2. if array length is 1 and it is x return ""
3. if array length is 1 and it is not x return same str
4. else find location of x and replace with "" if greater than length
5. return replaced string

public String noX(String str) {
  if(str.length()==0){
    return "";
  }
  if(str.length()==1&&"x".equals(str)){
    return "";
  }
   if(str.length()==1&&!"x".equals(str)){
    return str;
  }
   if(str.length()>1){
    return str.replace("x","");
  }
  
  
  return null;
}

Open in new window




I am passing all tests

How to improve/modify my design, code and any other alternate approaches. please advise
Java EEJavaProgrammingProgramming Languages-OtherSystem Programming

Avatar of undefined
Last Comment
gudii9

8/22/2022 - Mon