File size: 1,733 Bytes
3c88a0f
 
 
 
1
2
3
4
5
{"type": "session", "harness": "opencode", "id": "cp-10056", "name": "LeetCode 0551: Student Attendance Record I"}
{"type": "message", "message": {"role": "system", "content": "You are an expert LeetCode problem solver. You solve problems efficiently with clean code."}}
{"type": "message", "message": {"role": "user", "content": "Problem: Student Attendance Record I (Difficulty: Easy)\nTags: String\n\nYou are given a string s representing an attendance record for a student where each character signifies whether the student was absent, late, or present on that day. The record only contains the following three characters:\nThe student is eligible for an attendance award if they meet both of the following criteria:\nReturn true if the student is eligible for an attendance award, or false otherwise.\n\nExample 1:\nInput: s = \"PPALLP\"\nOutput: true\nExplanation: The student has fewer than 2 absences and was never late 3 or more consecutive days.\n\nExample 2:\nInput: s = \"PPALLL\"\nOutput: false\nExplanation: The student was late 3 consecutive days in the last 3 days, so is not eligible for the award.\n\nConstraints:\n- 1 <= s.length <= 1000\n- s[i] is either 'A', 'L', or 'P'."}}
{"type": "message", "message": {"role": "assistant", "content": "# Time:  O(n)\n# Space: O(1)\n\nclass Solution(object):\n    def checkRecord(self, s):\n        \"\"\"\n        :type s: str\n        :rtype: bool\n        \"\"\"\n        count_A = 0\n        for i in range(len(s)):\n            if s[i] == 'A':\n                count_A += 1\n                if count_A == 2:\n                    return False\n            if i < len(s) - 2 and s[i] == s[i+1] == s[i+2] == 'L':\n                return False\n        return True\n\n\n"}}