LeetCode 551. 学生出勤记录 I 解答

给定一个字符串来代表一个学生的出勤记录,这个记录仅包含以下三个字符:

    'A' : Absent,缺勤
    'L' : Late,迟到
    'P' : Present,到场

如果一个学生的出勤记录中不超过一个'A'(缺勤)并且不超过两个连续的'L'(迟到),那么这个学生会被奖赏。

你需要根据这个学生的出勤记录判断他是否会被奖赏。

class Solution {
public:
    bool checkRecord(string s) {
        int countA = 0;
        int countL = 0;
        for(int i = 0; i < s.size(); ++i)
        {
            if(s[i] == 'A')
                countA++;
            if(countA > 1)
                return false;
            if(s[i] == 'L')
            {
                countL++;
                if(countL > 2)
                    return false;
            }
            else
                countL = 0;
        }
        return true;
    }
};
发布了48 篇原创文章 · 获赞 29 · 访问量 9796

猜你喜欢

转载自blog.csdn.net/flyconley/article/details/102666222
今日推荐