# 551. Student Attendance Record I

You are given a string representing an attendance record for a student. The record only contains the following three characters:

1. ‘A’ : Absent.
2. ‘L’ : Late.
3. ‘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
``````

``````class Solution {
public:
bool checkRecord(string s) {
int cntA = 0, cntL = 0;
for (char c : s) {
if (c == 'A') {
if (++cntA > 1) return false;
cntL = 0;
} else if (c == 'L') {
if (++cntL > 2) return false;
} else {
cntL = 0;
}
}
return true;
}
};
``````

``````class Solution {
public:
bool checkRecord(string s) {
return (s.find("A") == string::npos || s.find("A") == s.rfind("A")) && s.find("LLL") == string::npos;
}
};
``````

``````class Solution {
public:
bool checkRecord(string s) {
return !regex_search(s, regex("A.*A|LLL"));
}
};
``````

https://discuss.leetcode.com/topic/86651/c-1-liner

https://discuss.leetcode.com/topic/86571/one-line-java-mixed-solution

https://discuss.leetcode.com/topic/86534/tiny-ruby-short-python-java-c/2

LeetCode All in One 题目讲解汇总(持续更新中…)

 微信打赏 Venmo 打赏
（欢迎加入博主的知识星球，博主将及时答疑解惑，并分享刷题经验与总结，试运营期间前五十位可享受半价优惠～）

×

Help us with donation