[leetcode]551. Student Attendance Record I
Analysis
中午吃啥?—— [明天要回家啦,嘻嘻~]
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.
比较简单,就按照他给的条件判断就行了,第一缺勤数至多只能有一次,第二就是不能连续迟到三次。
Implement
class Solution {
public:
bool checkRecord(string s) {
int countA = 0;
int len = s.length();
for(int i=0; i<len; i++){
if(s[i] == 'A'){
countA++;
if(countA>1)
return false;
}
if(s[i] == 'L'){
if(i-1>=0 && i+1<len && s[i-1]=='L' && s[i+1]=='L')
return false;
}
}
return true;
}
};