[LeetCode] 1910. Remove All Occurrences of a Substring
2663 ワード
に答える
indexOfを用いて無限ループ中のs内にpartがあるかどうかを解く
コード#コード# /**
* @param {string} s
* @param {string} part
* @return {string}
*/
var removeOccurrences = function(s, part) {
// 무한루프
while(true){
// part가 있는지 체크
const index = s.indexOf(part);
if(index === -1){
// 없다면 탈출
break;
} else {
// 있다면 빈 문자열로 교체
s=s.replace(part,'')
}
}
return s;
};
整理する
ソース
https://leetcode.com/problems/remove-all-occurrences-of-a-substring/
Reference
この問題について([LeetCode] 1910. Remove All Occurrences of a Substring), 我々は、より多くの情報をここで見つけました
https://velog.io/@assash17/LeetCode-1910.-Remove-All-Occurrences-of-a-Substring
テキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol
/**
* @param {string} s
* @param {string} part
* @return {string}
*/
var removeOccurrences = function(s, part) {
// 무한루프
while(true){
// part가 있는지 체크
const index = s.indexOf(part);
if(index === -1){
// 없다면 탈출
break;
} else {
// 있다면 빈 문자열로 교체
s=s.replace(part,'')
}
}
return s;
};
整理する
ソース
https://leetcode.com/problems/remove-all-occurrences-of-a-substring/
Reference
この問題について([LeetCode] 1910. Remove All Occurrences of a Substring), 我々は、より多くの情報をここで見つけました
https://velog.io/@assash17/LeetCode-1910.-Remove-All-Occurrences-of-a-Substring
テキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol
https://leetcode.com/problems/remove-all-occurrences-of-a-substring/
Reference
この問題について([LeetCode] 1910. Remove All Occurrences of a Substring), 我々は、より多くの情報をここで見つけました https://velog.io/@assash17/LeetCode-1910.-Remove-All-Occurrences-of-a-Substringテキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol