java.lang.Object
g2101_2200.s2124_check_if_all_as_appears_before_all_bs.Solution

public class Solution extends Object
2124 - Check if All A&rsquo;s Appears Before All B&rsquo;s.<p>Easy</p> <p>Given a string <code>s</code> consisting of <strong>only</strong> the characters <code>'a'</code> and <code>'b'</code>, return <code>true</code> <em>if <strong>every</strong></em> <code>'a'</code> <em>appears before <strong>every</strong></em> <code>'b'</code> <em>in the string</em>. Otherwise, return <code>false</code>.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> s = &ldquo;aaabbb&rdquo;</p> <p><strong>Output:</strong> true</p> <p><strong>Explanation:</strong></p> <p>The &rsquo;a&rsquo;s are at indices 0, 1, and 2, while the &rsquo;b&rsquo;s are at indices 3, 4, and 5.</p> <p>Hence, every &lsquo;a&rsquo; appears before every &lsquo;b&rsquo; and we return true.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> s = &ldquo;abab&rdquo;</p> <p><strong>Output:</strong> false</p> <p><strong>Explanation:</strong></p> <p>There is an &lsquo;a&rsquo; at index 2 and a &lsquo;b&rsquo; at index 1.</p> <p>Hence, not every &lsquo;a&rsquo; appears before every &lsquo;b&rsquo; and we return false.</p> <p><strong>Example 3:</strong></p> <p><strong>Input:</strong> s = &ldquo;bbb&rdquo;</p> <p><strong>Output:</strong> true</p> <p><strong>Explanation:</strong> There are no &rsquo;a&rsquo;s, hence, every &lsquo;a&rsquo; appears before every &lsquo;b&rsquo; and we return true.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= s.length <= 100</code></li> <li><code>s[i]</code> is either <code>'a'</code> or <code>'b'</code>.</li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • checkString

      public boolean checkString(String s)