1、按题目要求判断即可,用acnt记录A的个数,用lcnt记录连续L的个数。
class Solution {
public:
bool checkRecord(string s) {
int acnt=0,lcnt=0;
for(int i=0;s[i];++i)
{
if(s[i]=='A')
{
++acnt;
if(acnt>=2) return false;
}
if(s[i]=='L') ++lcnt;
else
{
if(lcnt>=3)return false;
lcnt=0;
}
}
if(lcnt>=3) return false;
return true;
}
};