Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit cd23e21

Browse files
committed
[Optimize the code]: Have implemented the program to find the final string after removing all the occurrences of a substring:.
1 parent c2f6be7 commit cd23e21

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

src/com/raj/RemoveAllOccurrencesOfASubstring.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,16 @@ public static void main(String[] args) {
1515
recursiveStringReplace(ans, part);
1616

1717
// Display the result.
18-
System.out.println("The final string after removing all the occurrences of a substring: " + ans+".");
18+
System.out.println("The final string after removing all the occurrences of a substring: " + ans + ".");
1919
}
2020

2121
// Recursive call the function itself to replace the string with the part.
22-
private static StringBuilder recursiveStringReplace(StringBuilder s, String part) {
22+
private static void recursiveStringReplace(StringBuilder s, String part) {
2323
for (int i = 0; i <= s.length() - part.length(); i++) {
2424
if (s.substring(i, i + part.length()).equals(part)) {
25-
s = s.delete(i, i + part.length());
25+
s.delete(i, i + part.length());
2626
recursiveStringReplace(s, part);
2727
}
2828
}
29-
return s;
3029
}
3130
}

0 commit comments

Comments
 (0)