C语言 | Leetcode C语言题解之第551题学生出勤记录I
题目:
题解:
bool checkRecord(char* s) {
int absents = 0, lates = 0;
int n = strlen(s);
for (int i = 0; i < n; i++) {
char c = s[i];
if (c == 'A') {
absents++;
if (absents >= 2) {
return false;
}
}
if (c == 'L') {
lates++;
if (lates >= 3) {
return false;
}
} else {
lates = 0;
}
}
return true;
}