2025-08-17 10:41:15 +0000 UTC

Check if All A’s Appears Before All B’s

Code

class Solution:
    def checkString(self, s: str) -> bool:
        found_a = False
        found_b = False
        for char in s:
            if char == "a":
                if found_b:
                    return False
                if not found_a:
                    found_a = True
            else:
                if not found_b:
                    found_b = True
        return True