Loading

leetcode551. 学生出勤记录 I

题目链接: https://leetcode-cn.com/problems/student-attendance-record-i/

今天的题很简单,应该没有人不会做,贴一下自己的代码

class Solution {
public:
    bool checkRecord(string s) {
        int A = 0, L = 0, len = s.length();
        for(int i = 0; i < len; i++)
        {
            char ch = s[i];
            if(ch == 'A') {
                A++;
                if(A >= 2) return false;
                L = 0;
            }
            if(ch == 'P'){
                L = 0;
            }
            if(ch == 'L'){
                L++;
                if(L >= 3) return false;
            }
        }
        return true;
    }
};
posted @ 2021-08-17 12:19  泠枫Jun  阅读(23)  评论(0编辑  收藏  举报