The Student Attendance Record I solutions are below.
15 Jun 2024•Easy•C++ / Python / TypeScript
Student Attendance Record I
C++, Python and TypeScript solutions for Student Attendance Record I.
Solution files
Python•student-attendance-record-i/synced-solution.py
class Solution:
def checkRecord(self, s: str) -> bool:
return s.count("A") < 2 and "LLL" not in s
C++•student-attendance-record-i/synced-solution.cpp
class Solution {
public:
bool checkRecord(string s) {
int absences = 0;
int consecutiveLate = 0;
for (char c : s) {
if (c == 'A') {
absences++;
consecutiveLate = 0;
if (absences >= 2) {
return false;
}
} else if (c == 'L') {
consecutiveLate++;
if (consecutiveLate >= 3) {
return false;
}
} else {
consecutiveLate = 0;
}
}
return true;
}
};
TypeScript•student-attendance-record-i/synced-solution.ts
function checkRecord(s: string): boolean {
let absences = 0;
let consecutiveLate = 0;
for (const ch of s) {
if (ch === "A") {
absences++;
consecutiveLate = 0;
if (absences >= 2) {
return false;
}
} else if (ch === "L") {
consecutiveLate++;
if (consecutiveLate >= 3) {
return false;
}
} else {
consecutiveLate = 0;
}
}
return true;
}