Leetcode 2243 Solution
This article provides solution to leetcode question 2243 (check-if-all-as-appears-before-all-bs)
Access this page by simply typing in "lcs 2243" in your browser address bar if you have bunnylol configured.
Leetcode Question Link
https://leetcode.com/problems/check-if-all-as-appears-before-all-bs
Solution
class Solution:
def checkString(self, s: str) -> bool:
state = 1
for ch in s:
if ch == 'a':
if state == 2:
return False
else:
state = 1
elif ch == 'b':
state = 2
return True