Skip to content

Commit f0ec9f4

Browse files
committed
[Use of Math.max]: Have implemented the program to find the final string after removing all the occurrences of a substring.
1 parent 8e65179 commit f0ec9f4

File tree

1 file changed

+1
-5
lines changed

1 file changed

+1
-5
lines changed

src/com/raj/RemoveAllOccurrencesOfASubstring.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,7 @@ private static void recursiveStringReplace(StringBuilder s, String part, int sta
2323
for (int i = startIndex; i <= s.length() - part.length(); i++) {
2424
if (s.substring(i, i + part.length()).equals(part)) {
2525
s.delete(i, i + part.length());
26-
if (i - part.length() > 0) {
27-
startIndex = i - part.length();
28-
} else {
29-
startIndex = 0;
30-
}
26+
startIndex = Math.max(i - part.length(), 0);
3127
recursiveStringReplace(s, part, startIndex);
3228
}
3329
}

0 commit comments

Comments
 (0)