努力刷题day15
LeetCode 551.学生出勤记录1 传送门
class Solution {
public boolean checkRecord(String s) {
int absents = 0, lates = 0;
int n = s.length();
for (int i = 0; i < n; i++) {
char c = s.charAt(i);
if (c == 'A') {
absents++;
if (absents >= 2) {
return false;
}
}
if (c == 'L') {
lates++;
if (lates >= 3) {
return false;
}
} else {
lates = 0;
}
}
return true;
}
}
LeetCode 1446.连续字符串 传送门
//双指针模拟
class Solution {
public int maxPower(String s) {
int maxPower = 1;
int len = s.length();
for (int i = 0; i < len; i++) {
int cnt = 1;
for (int j = i + 1; j < len; j++) {
if (s.charAt(i) == s.charAt(j)) {
cnt++;
if (cnt > maxPower) {
maxPower = cnt;
}
} else {
cnt = 1;
break;
}
}
}
return maxPower;
}
}