Monday, January 2, 2023
Student Attendance Record I
Go
- Time complexity: - n is a length of a string
- Auxiliary space: - constant amount of space
func checkRecord(s string) bool {
consLateCount := 0
absentCount := 0
result := true
for _, rune := range s {
if string(rune) == "L" {
consLateCount++
} else {
consLateCount = 0
}
if string(rune) == "A" {
absentCount++
}
if consLateCount > 2 || absentCount > 1 {
result = false
break
}
}
return result
}