Leetcode 2243 Solution

This article provides solution to leetcode question 2243 (check-if-all-as-appears-before-all-bs)

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