Created
April 2, 2020 20:28
-
-
Save Camshaft54/4408188752d65cd2ed89a4135de52e97 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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