> For the complete documentation index, see [llms.txt](https://timmybeeflin.gitbook.io/cracking-leetcode/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://timmybeeflin.gitbook.io/cracking-leetcode/weekly-contest/weekly-contest-274/2124.-check-if-all-as-appears-before-all-bs.md).

# 2124. Check if All A's Appears Before All B's

T: O(n)

S: O(1)

```java
class Solution {
    public boolean checkString(String s) {
        boolean foundB = false;
        for (char c : s.toCharArray()) {
            if (c == 'b') {
                foundB = true;
            } else if (foundB && c == 'a') {
                return false;
            }
        }
        return true;
    }
}
```
