Skip to content

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

  • Time: $O(n)$
  • Space: $O(n)$
1
2
3
4
5
6
class Solution {
 public:
  bool checkString(string s) {
    return s.find("ba") == string::npos;
  }
};
1
2
3
4
5
class Solution {
  public boolean checkString(String s) {
    return !s.contains("ba");
  }
}
1
2
3
class Solution:
  def checkString(self, s: str) -> bool:
    return 'ba' not in s
Back to top