标签:string ret enum more pretty 1.4 ext com overflow
You are given a string representing an attendance record for a student. The record only contains the following three characters:
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
Subscribe to see which companies asked this question.
public class Solution {
public bool CheckRecord(string s) {
int lateNum = 0;
int absentNum = 0;
foreach(var i in s) {
if (i == ‘L‘) {
lateNum++;
} else {
lateNum = 0;
if (i == ‘A‘) {
absentNum++;
}
}
if (absentNum > 1 || lateNum > 2) {
return false;
}
}
return true;
}
}
551. 学生出席记录 Student Attendance Record I
标签:string ret enum more pretty 1.4 ext com overflow
原文地址:http://www.cnblogs.com/xiejunzhao/p/c443136ace718cd8494bfcdaa48f1338.html