Untitled
unknown
plain_text
2 years ago
890 B
12
Indexable
class Solution:
def removeStars(self, s: str) -> str:
left=len(s)-1
right=len(s)-1
to_remove=0
result_array = []
while left>=0 and right>=0:
if s[left]=='*':
left-=1
to_remove += 1
continue
if s[left] != '*':
if right > left:
print(f's: {s}')
# remaining = s[right+1:len(s)] if right < len(s) else ''
# s=s[:left] + remaining
left -= to_remove
right = left
to_remove = 0
else: #no stars attached
result_array.insert(0, s[left])
left-=1
right-=1
res = ''.join(result_array)
return res
Editor is loading...
Leave a Comment