MCPcopy Create free account
hub / github.com/Tiwarishashwat/InterviewCodes / Solution

Class Solution

RemoveAllOccurrencesOfASubstring.java:1–17  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1class Solution {
2 public String removeOccurrences(String s, String part) {
3 StringBuilder sb = new StringBuilder();
4 int n = s.length();
5 int m = part.length();
6 for(char ch : s.toCharArray()){
7 sb.append(ch);
8 if(sb.length() >= m){
9 String sub = sb.substring(sb.length()-m);
10 if(sub.equals(part)){
11 sb.setLength(sb.length()-m);
12 }
13 }
14 }
15 return sb.toString();
16 }
17}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected