image_2021-11-02_15-23-58.png
52.8 KB
#N551. Student Attendance Record I
problem link=>https://leetcode.com/problems/student-attendance-record-i/
#solution
problem link=>https://leetcode.com/problems/student-attendance-record-i/
#solution
class Solution {
public boolean checkRecord(String s) {
char[] ch=s.toCharArray();
int isLate=1;
int isAbsent=0;
for(int i=0; i<ch.length; i++){
if(ch[i]=='A'){
isAbsent++;
}
}
for(int i=0; i<ch.length-1;i++){
if(ch[i]=='L'&&ch[i+1]=='L'){
isLate++;
if(isLate==3)
return false;
}
else if(ch[i]!='L'&&ch[i+1]=='L'){
isLate=1;
}
}
return isAbsent<2 && isLate<3;
}
}