551 Student Attendance Record I
Problem:
Input: "PPALLP"
Output: TrueInput: "PPALLL"
Output: FalseSolutions:
public class Solution {
public boolean checkRecord(String s) {
boolean hasA = false;
int countL = 0;
for (int i = 0; i < s.length(); i ++) {
char c = s.charAt(i);
if (c == 'A') {
if (hasA == true) {
return false;
}
hasA = true;
}
if (c == 'L') {
countL ++;
if (countL == 3) {
return false;
}
}
else {
countL = 0;
}
}
return true;
}
}Last updated