[Leetcode]2124. Check if All A's Appears Before All B's
📄 Description
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.
Example 1:
Input: s = "aaabbb"
Output: true
Explanation:
The 'a's are at indices 0, 1, and 2, while the 'b's are at indices 3, 4, and 5.
Hence, every 'a' appears before every 'b' and we return true.Example 2:
Input: s = "abab"
Output: false
Explanation:
There is an 'a' at index 2 and a 'b' at index 1.
Hence, not every 'a' appears before every 'b' and we return false.Example 3:
Input: s = "bbb"
Output: true
Explanation:
There are no 'a's, hence, every 'a' appears before every 'b' and we return true.Constraints:
- 1 <= s.length <= 100
- s[i]is either- 'a'or- 'b'.
💻 My Submission
class Solution:
    def checkString(self, s: str) -> bool:
        if 'a' and 'b' in s:
            start_b=s.index('b')
            if 'a' in s[start_b:]:
                return False
        return True💭 Better Solution(1)
class Solution:
    def checkString(self, s: str) -> bool:
        return "ba" not in s💭 Better Solution(2)
class Solution:
    checkString = re.compile('a*b*').fullmatch- fullmatch(): 문자열 전부가 매치되는가를 체크
💡 What I learned
References
Author And Source
이 문제에 관하여([Leetcode]2124. Check if All A's Appears Before All B's), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://velog.io/@limelimejiwon/Leetcode2124.-Check-if-All-As-Appears-Before-All-Bs저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
                                
                                
                                
                                
                                
                                우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)