Skip to content

Latest commit

 

History

History
34 lines (27 loc) · 641 Bytes

Question_2124.md

File metadata and controls

34 lines (27 loc) · 641 Bytes

LeetCode Records - Question 2124 Check if All A's Appears Before All B's

Attempt 1: Use two loops

class Solution {
    public boolean checkString(String s) {
        char[] arr = s.toCharArray();

        int i = 0;
        while (i < arr.length) {
            if (arr[i] == 'b') {
                break;
            }

            i++;
        }
        i++;

        while (i < arr.length) {
            if (arr[i] != 'b') {
                return false;
            }

            i++;
        }

        return true;
    }
}
  • Runtime: 0 ms (Beats: 100.00%)
  • Memory: 41.44 MB (Beats: 40.31%)