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).
class Solution(object):
def checkRecord(self, s):
"""
:type s: str
:rtype: bool
"""
if not s: return None
c = collections.Counter(s)
if c['A']>1: return False
count = 0
for i in range(2, len(s)):
if s[i]==s[i-1]==s[i-2]=='L':
return False
return True
1 分别判断两种情况,一种是A的情况,一种是L的情况
2 对于A,可用collections.Counter(s)得出每种情况的个数,如果A大于1,则返回Fasle
3 if c['A']>1: return False 注意c['A']要用中括号,而且里面字母用‘A’
4 对于L,则判断有没有连续三个L