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

T: O(n)

S: O(1)

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;
    }
}

Last updated