-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAttendanceAward.java
More file actions
39 lines (33 loc) · 1.06 KB
/
Copy pathAttendanceAward.java
File metadata and controls
39 lines (33 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package LeetcodePractice;
public class AttendanceAward {
public static void main(String[] args) {
System.out.println(checkRecord("PPALLP"));
System.out.println(checkRecord("PPALLL"));
System.out.println(checkRecord("LLL"));
System.out.println(checkRecord("P"));
System.out.println(checkRecord("A"));
System.out.println(checkRecord("AA"));
}
public static boolean checkRecord(String s) {
int absentCount = 0;
int consecutiveLates = 0;
for (int i = 0; i < s.length(); i++) {
char c = s.charAt(i);
if (c == 'A') {
absentCount++;
if (absentCount >= 2) {
return false;
}
consecutiveLates = 0;
} else if (c == 'L') {
consecutiveLates++;
if (consecutiveLates >= 3) {
return false;
}
} else {
consecutiveLates = 0;
}
}
return true;
}
}