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

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

Leetcode Solutions

Linear Scan for 'a' after 'b'

  1. Initialize a boolean variable foundB to false to track if we have encountered a 'b'.
  2. Iterate through each character in the string s.
  3. If the current character is 'b', set foundB to true.
  4. If the current character is 'a' and foundB is true, return false as we have found an 'a' after a 'b'.
  5. If we finish iterating through the string without returning false, return true.
UML Thumbnail

Check for 'b' followed by 'a'

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...