力扣题-12.5
力扣题1:551. 学生出勤记录 I
解题思想:进行字符的统计即可
class Solution(object):
def checkRecord(self, s):
"""
:type s: str
:rtype: bool
"""
flag = True
count_A = 0
count_L = 0
for i in range(len(s)):
if s[i]=='A':
count_A +=1
count_L = 0
elif s[i]=='L':
count_L +=1
if count_L >=3:
flag = False
else:
count_L = 0
if count_A>=2:
flag = False
return flag
class Solution {
public:
bool checkRecord(string s) {
bool flag = true;
int count_A = 0;
int count_L = 0;
for (int i = 0; i < s.length(); ++i) {
if (s[i] == 'A') {
count_A++;
count_L = 0;
} else if (s[i] == 'L') {
count_L++;
if (count_L >= 3) {
flag = false;
}
} else {
count_L = 0;
}
}
if (count_A >= 2) {
flag = false;
}
return flag;
}
};