Skip to content

Commit b01b962

Browse files
committed
Add solution #1910
1 parent 653b2a4 commit b01b962

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,7 @@
492492
1833|[Maximum Ice Cream Bars](./1833-maximum-ice-cream-bars.js)|Medium|
493493
1880|[Check if Word Equals Summation of Two Words](./1880-check-if-word-equals-summation-of-two-words.js)|Easy|
494494
1886|[Determine Whether Matrix Can Be Obtained By Rotation](./1886-determine-whether-matrix-can-be-obtained-by-rotation.js)|Easy|
495+
1910|[Remove All Occurrences of a Substring](./1910-remove-all-occurrences-of-a-substring.js)|Medium|
495496
1920|[Build Array from Permutation](./1920-build-array-from-permutation.js)|Easy|
496497
1929|[Concatenation of Array](./1929-concatenation-of-array.js)|Easy|
497498
1935|[Maximum Number of Words You Can Type](./1935-maximum-number-of-words-you-can-type.js)|Easy|
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* 1910. Remove All Occurrences of a Substring
3+
* https://leetcode.com/problems/remove-all-occurrences-of-a-substring/
4+
* Difficulty: Medium
5+
*
6+
* Given two strings s and part, perform the following operation on s until all occurrences of
7+
* the substring part are removed:
8+
* - Find the leftmost occurrence of the substring part and remove it from s.
9+
*
10+
* Return s after removing all occurrences of part.
11+
*
12+
* A substring is a contiguous sequence of characters in a string.
13+
*/
14+
15+
/**
16+
* @param {string} s
17+
* @param {string} part
18+
* @return {string}
19+
*/
20+
var removeOccurrences = function(s, part) {
21+
while (s.includes(part)) {
22+
s = s.replace(part, '');
23+
}
24+
return s;
25+
};

0 commit comments

Comments
 (0)