# 551. Student Attendance Record I

**<font color=red>难度: Easy</font>**

## 刷题内容

> 原题连接

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

> 内容描述

```

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
```

## 解题方案

> 思路 1
******- 时间复杂度: O(N)******- 空间复杂度: O(1)******


一次遍历，beats 99.11%

```python
class Solution:
    def checkRecord(self, s):
        """
        :type s: str
        :rtype: bool
        """
        cnt_a = 0
        for i, c in enumerate(s):
            if c == 'A':
                cnt_a += 1
                if cnt_a > 1:
                    return False
            elif c == 'L':
                if i > 1 and s[i-1] == 'L' and s[i-2] == 'L':
                    return False
        return True
```



























