You are given a string representing an attendance record for a student. The record only contains the following three characters:
- 'A' : Absent.
- 'L' : Late.
- 'P' : Present.
A student could be rewarded if his attendance record doesn't contain more than one 'A' (absent) or more than two continuous 'L' (late).
You need to return whether the student could be rewarded according to his attendance record.
如果字符串中包含的A超过1或者有连续2个以上的L,就输出false
C++(3ms):
1 class Solution { 2 public: 3 bool checkRecord(string s) { 4 int numA = 0 ; 5 int numL = 0 ; 6 for (auto t : s){ 7 if (t == 'A') 8 numA++ ; 9 if(t == 'L') 10 numL++; 11 else 12 numL = 0 ; 13 if(numA>1 || numL>2) 14 return false ; 15 } 16 return true ; 17 } 18 };