LeetCode 551. Student Attendance Record I 学生出勤纪录 I

链接

https://leetcode-cn.com/problems/student-attendance-record-i/description/

要求

给定一个字符串来代表一个学生的出勤纪录,这个纪录仅包含以下三个字符:

'A' : Absent,缺勤
'L' : Late,迟到
'P' : Present,到场
如果一个学生的出勤纪录中不超过一个'A'(缺勤)并且不超过两个连续的'L'(迟到),那么这个学生会被奖赏。

你需要根据这个学生的出勤纪录判断他是否会被奖赏。

输入: "PPALLP"
输出: True

输入: "PPALLL"
输出: False

相关代码

思路:
主要考察布尔值掌握能力。按要求列好条件即可,注意'LL'有连续限定条件,所以不能用count。

class Solution(object):
    def checkRecord(self, s):
        return s.count('A') <= 1 and 'LLL' not in s

你可能感兴趣的:(LeetCode 551. Student Attendance Record I 学生出勤纪录 I)