- '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.
Example 1:
Input: "PPALLP" Output: True
Example 2:
Input: "PPALLL" Output: False
A:
----------------------就是题目的理解一开始有错误。-----------no more than 2 continuous Late---------class Solution { public: bool checkRecord(string s) { int cA = 0; int contiL = 0; for(auto c : s) { if(c =='A') { cA++; contiL = 0; if(cA>1) break; }else if(c=='L') { if(contiL) { contiL++; if(contiL >=3) break; }else{ contiL = 1; } }else{ contiL = 0; } } return cA<=1 and contiL < 3; } };
No comments:
Post a Comment