class Solution {
public boolean checkRecord(String s) {
int len=s.length();
int countA=0;
int countL=0;
for (int i = 0; i < len; i++) {
if(s.charAt(i)=='A') countA++;
if(s.charAt(i)=='L') {
countL++;
if(countL>2) return false;
}
else countL=0;//方便计算连续的L,countL这个地方设计的使用,开心,想到这样用。
}
if(countA>1) return false;
return true;
}
}
Leetcode 551. 学生出勤记录 I
最新推荐文章于 2022-03-12 13:52:00 发布