반응형
Description:
Remove n exclamation marks in the sentence from left to right. n is positive integer.
Examples
remove("Hi!",1) === "Hi"
remove("Hi!",100) === "Hi"
remove("Hi!!!",1) === "Hi!!"
remove("Hi!!!",100) === "Hi"
remove("!Hi",1) === "Hi"
remove("!Hi!",1) === "Hi!"
remove("!Hi!",100) === "Hi"
remove("!!!Hi !!hi!!! !hi",1) === "!!Hi !!hi!!! !hi"
remove("!!!Hi !!hi!!! !hi",3) === "Hi !!hi!!! !hi"
remove("!!!Hi !!hi!!! !hi",5) === "Hi hi!!! !hi"
remove("!!!Hi !!hi!!! !hi",100) === "Hi hi hi"
Solution:
def remove(s: str, n: int) -> str:
return s.replace("!", "", n)
반응형
'나는 이렇게 학습한다 > Algorithm & SQL' 카테고리의 다른 글
1116. Convert boolean values to strings 'Yes' or 'No'. (0) | 2022.11.17 |
---|---|
1115. Reversed Strings (0) | 2022.11.15 |
1113. Parse nice int from char problem (0) | 2022.11.13 |
1112. Sum of Multiples (0) | 2022.11.13 |
1111. Grasshopper - Debug sayHello (0) | 2022.11.12 |