Post

leetcode(리트코드)-1910 Remove All Occurrences of a Substring(PYTHON)

leetcode 1910 - Remove All Occurrences of a Substring 문제입니다.

1. 문제

https://leetcode.com/problems/remove-all-occurrences-of-a-substring/


2. Input , Output


3. 분류 및 난이도

Medium 난이도 문제입니다.


4. 문제 해석

  • input과 part가 주어집니다.
  • part를 input에서 찾아 모든 부분 문자열을 지워버린 문자열을 리턴합니다.

5. code

코드설명

python

1
2
3
4
5
6
7
8
9
10
11
class Solution:
    def removeOccurrences(self, s: str, part: str) -> str:
        size = len(part)
        while True : 
            idx = s.find(part)
            if idx == -1 : 
                break
            else : 
                s = s[:idx] + s[idx + size:]
        return s
            

6. 결과 및 후기, 개선점

This post is licensed under CC BY 4.0 by the author.