delDel
Problem:
Test Cases:
delDel("adelbc") → "abc"
delDel("adelHello") → "aHello"
delDel("adedbc") → "adedbc"
Solution:
public String delDel(String str) {
if(str.length()>=4)
{
if(str.substring(1,4).equals("del"))
{
return str.substring(0,1)+str.substring(4);
}
}
return str;
}
Problem:
Given a string, if the string "del" appears starting
at index 1, return a string where that "del" has been deleted.
Otherwise, return the string unchanged.
Test Cases:
delDel("adelbc") → "abc"
delDel("adelHello") → "aHello"
delDel("adedbc") → "adedbc"
Solution:
public String delDel(String str) {
if(str.length()>=4)
{
if(str.substring(1,4).equals("del"))
{
return str.substring(0,1)+str.substring(4);
}
}
return str;
}
No comments:
Post a Comment