Check If Word Is Valid After Substitutions LeetCode solution in Python

1
class Solution:
2
def isValid(self, s: str) -> bool:
3

4
ans = ""
5
for i in s:
6
ans += i
7
while len(ans) >= 3:
8
if ans[-3:] == "abc":
9
ans = ans[0:-3]
10
else:
11
break
12

13
if ans == "":
14
return True
15
else:
16
return False

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0