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

@problem@discussion
#String



1/**
2 * [2124] Check if All A's Appears Before All B's
3 *
4 * Given a string s consisting of only the characters 'a' and 'b', return true if every 'a' appears before every 'b' in the string. Otherwise, return false.
5 *  
6 * Example 1:
7 * 
8 * Input: s = "aaabbb"
9 * Output: true
10 * Explanation:
11 * The 'a's are at indices 0, 1, and 2, while the 'b's are at indices 3, 4, and 5.
12 * Hence, every 'a' appears before every 'b' and we return true.
13 * 
14 * Example 2:
15 * 
16 * Input: s = "abab"
17 * Output: false
18 * Explanation:
19 * There is an 'a' at index 2 and a 'b' at index 1.
20 * Hence, not every 'a' appears before every 'b' and we return false.
21 * 
22 * Example 3:
23 * 
24 * Input: s = "bbb"
25 * Output: true
26 * Explanation:
27 * There are no 'a's, hence, every 'a' appears before every 'b' and we return true.
28 * 
29 *  
30 * Constraints:
31 * 
32 * 	1 <= s.length <= 100
33 * 	s[i] is either 'a' or 'b'.
34 * 
35 */
36pub struct Solution {}
37
38// problem: https://leetcode.com/problems/check-if-all-as-appears-before-all-bs/
39// discuss: https://leetcode.com/problems/check-if-all-as-appears-before-all-bs/discuss/?currentPage=1&orderBy=most_votes&query=
40
41// submission codes start here
42
43impl Solution {
44    pub fn check_string(s: String) -> bool {
45        false
46    }
47}
48
49// submission codes end
50
51#[cfg(test)]
52mod tests {
53    use super::*;
54
55    #[test]
56    fn test_2124() {
57    }
58}
59


Back
© 2025 bowen.ge All Rights Reserved.