class Solution {
public boolean checkRecord(String s) {
int countL =0;
int countA = 0;
int i =0;
while(i<s.length())
{
char ch = s.charAt(i);
if(ch=='A')
{
countA++;
if(countA>=2) return false;
i++;
}
else if(ch=='L')
{
while(i<s.length()&&s.charAt(i)=='L')
{
countL++;
i++;
}
if(countL>=3) return false;
else countL=0;
}
else
i++;
}
return true;
}
}
网友评论