解法一:
public class Solution {
//A student could be rewarded if his attendance record doesn't contain more than one 'A' (absent)
//or more than two [continuous] 'L' (late). 对L的要求是[连续]超过2次
public boolean checkRecord(String s) {
int countA = 0;
int countL = 0;//这个代表最大的countL
int curCountL = 0;//这个代表当前连续的curCountL
for(int i = 0; i < s.length(); i++){
if(s.charAt(i) == 'A'){
countA++;
}
if(s.charAt(i) == 'L'){
curCountL++;
countL = Math.max(countL, curCountL);
} else{
curCountL = 0;
}
//System.out.println("countA:" + countA + " countL:" + countL + " curCountL:" + curCountL);
}
if(countA > 1 || countL > 2){
return false;
} else{
return true;
}
}
}