551. Student Attendance Record I - easy
문제
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.
제한사항
입출력 예
1
2
3
4
Example 1:
Input: "PPALLP"
Output: True
1
2
3
4
Example 2:
Input: "PPALLL"
Output: False
풀이
- Arrary
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
class Solution {
public:
bool checkRecord(string s) {
int a_count = 0;
int l_count = 0;
for(const auto& i : s){
if(i == 'A'){
++a_count;
l_count = 0;
}
else if(i == 'L')
++l_count;
else
l_count = 0;
if(a_count > 1 || l_count > 2)
return false;
}
return true;
}
};