나는 이렇게 학습한다/Algorithm & SQL

1114. Exclamation marks series #6: Remove n exclamation marks in the sentence from left to right

daco2020 2022. 11. 14. 21:50
반응형

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)


반응형