Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
28-liner: 3 easy examples solution in Clear category for Backspace Apply by przemyslaw.daniel
def backspace_apply(text: str) -> str:
""" Simple processing """
result = []
for char in text:
if char == "#":
result = result[:-1]
else:
result += [char]
return ''.join(result)
def backspace_apply(text: str) -> str:
""" Using regular re library """
import re
while "#" in text:
text = re.sub(r"[^#]#|^#", "", text)
return text
def backspace_apply(text: str) -> str:
""" Recursive example """
if "#" not in text:
return text
left, _, right = text.partition("#")
return backspace_apply(left[:-1] + right)
Dec. 9, 2021
Comments: