Skip to content

Latest commit

 

History

History
28 lines (26 loc) · 629 Bytes

551.md

File metadata and controls

28 lines (26 loc) · 629 Bytes

551. Student Attendance Record I

Solution 1 (time O(n), space O(1))

class Solution(object):
    def checkRecord(self, s):
        """
        :type s: str
        :rtype: bool
        """
        a_count = 0
        l_count = 0
        l_count_flag = False
        for c in s:
            if c == "A":
                a_count += 1
            if c == "L":
                l_count += 1
                if l_count >= 3:
                    l_count_flag = True
            else:
                l_count = 0
        if a_count >= 2 or l_count_flag:
            return False
        else:
            return True