public class Solution { public bool CheckRecord(string s) { var Absent = 0; var MaxLate = 0; var ContiLate = 0; var preChar = '\0'; for (int i = 0; i < s.Length; i++) { var c = s[i]; if (c == 'A') { Absent++; preChar = c; if (MaxLate < ContiLate) { MaxLate = ContiLate; } ContiLate = 0; } else if (c == 'L') { if (ContiLate == 0) { ContiLate = 1; preChar = c; } else { if (preChar == c) { ContiLate++; preChar = c; } else { ContiLate = 0; preChar = c; } } } else { if (MaxLate < ContiLate) { MaxLate = ContiLate; } ContiLate = 0; } } if (MaxLate < ContiLate) { MaxLate = ContiLate; } if (Absent > 1 || MaxLate > 2) { return false; } else { return true; } } }
https://leetcode.com/problems/student-attendance-record-i/#/description