Skip to content

Instantly share code, notes, and snippets.

@Camshaft54
Created April 2, 2020 20:27
Show Gist options
  • Save Camshaft54/2480c9056369cd9f28412e824c40c29c to your computer and use it in GitHub Desktop.
Save Camshaft54/2480c9056369cd9f28412e824c40c29c to your computer and use it in GitHub Desktop.
starOut Solution CodingBat
public String starOut(String str) {
String newStr = "";
int[] stars = new int[str.length()];
for (int i = 0; i < str.length(); i++) {
if (str.substring(i, i+1).equals("*")) {
if (i != 0) {
stars[i-1] = 1;
}
stars[i] = 1;
if (i + 1 < stars.length) {
stars[i+1] = 1;
}
}
}
for (int j = 0; j < str.length(); j++) {
if (stars[j] == 0)
newStr += str.substring(j, j + 1);
}
return newStr;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment