class Solution:
def removeStars(self, s: str) -> str:
s=list(s)
n=s.count('*')
for i in range(n):
j=s.index('*')
if j==0:
s.pop(j)
elif s[j-1]!='*':
s.pop(j)
s.pop(j-1)
else:
s.pop(j)
res=''
for i in s:
res=res+i
return res
Exceeding Time Limit
class Solution:
def removeStars(self, s: str) -> str:
n=s.count('*')
for i in range(n):
j=s.index('*')
if j==0:
s=s[:j]+s[j+1:]
elif s[j-1]!='*':
s=s[:j-1]+s[j+1:]
else:
s=s[:j]+s[j+1:]
return s
class Solution:
def removeStars(self, s: str) -> str:
l=''
for i in s:
if i=='*':
l=l[:-1]
else:
l=l+i
return l