1910.js
/** ------------------------------------------------------------------------------
*
* 1910. Remove All Occurrences of a Substring
* Topics: String, Stack
* https://leetcode.com/problems/remove-all-occurrences-of-a-substring/?envType=daily-question&envId=2025-02-11
*
------------------------------------------------------------------------------ */
/**
* @param {string} s
* @param {string} part
* @return {string}
*/
var removeOccurrences = function (s, part) {
while (s.includes(part)) {
s = s.replace(part, "")
}
return s
}
var removeOccurrences = function (s, part) {
let idx = s.indexOf(part)
while (idx != -1) {
s = s.substring(0, idx) + s.substring(idx + part.length)
idx = s.indexOf(part)
}
return s
}
console.log(removeOccurrences("daabcbaabcbc", "abc"))