題目
You are given a string representing an attendance record for a student. The record only contains the following three characters:
- 'A' : Absent.
- 'L' : Late.
- 'P' : Present.
A student could be rewarded if his attendance record doesn't contain more than one 'A' (absent) or more than two continuous 'L' (late).
You need to return whether the student could be rewarded according to his attendance record.
Example 1:
Input: "PPALLP"
Output: True
Example 2:
Input: "PPALLL"
Output: False
難度
Easy
方法
對(duì)'A'
和'L'
計(jì)數(shù)寓落,如果'A'
出現(xiàn)的次數(shù)>1
,返回False
;如果'L'
連續(xù)出現(xiàn)的次數(shù)>2
礁苗,則返回False
胖烛;其他情況返回True
python代碼
class Solution(object):
def checkRecord(self, s):
"""
:type s: str
:rtype: bool
"""
a_count = 0
l_count = 0
for c in s:
if c == "A":
a_count += 1
l_count = 0
if a_count > 1:
return False
elif c == "L":
l_count += 1
if l_count > 2:
return False
else:
l_count = 0
return True
assert Solution().checkRecord("PPALLP") == True
assert Solution().checkRecord("PPALLL") == False
assert Solution().checkRecord("ALPP") == True