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

Commit 8e65179

Browse files
committed
[Fixed the invalid string]: Have implemented the program to find the final string after removing all the occurrences of a substring:.
1 parent c74d8f8 commit 8e65179

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

.idea/workspace.xml

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/com/raj/RemoveAllOccurrencesOfASubstring.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
public class RemoveAllOccurrencesOfASubstring {
88
public static void main(String[] args) {
99
// Initialization.
10-
String s = "daabcbaabcbc";
11-
String part = "abc";
10+
String s = "kirkirkirpgpgpkirpgkirkirpgkirpgkikikirpgrpgrkirpkirpgkirpggpgpkikirpgrkirkirpgpgpggkikirpgrpggkirpgbkirpgthytpyimz";
11+
String part = "kirpg";
1212
StringBuilder ans = new StringBuilder(s);
1313

1414
// Logic.
@@ -25,6 +25,8 @@ private static void recursiveStringReplace(StringBuilder s, String part, int sta
2525
s.delete(i, i + part.length());
2626
if (i - part.length() > 0) {
2727
startIndex = i - part.length();
28+
} else {
29+
startIndex = 0;
2830
}
2931
recursiveStringReplace(s, part, startIndex);
3032
}

0 commit comments

Comments
 (0)