【leetcode_easy】551. Student Attendance Record I

problem

551. Student Attendance Record I

 题意:

solution:

class Solution {
public:
    bool checkRecord(string s) {
        int cntA = 0;
        int cntL = 0;
        for(auto ch:s)
        {
            if('A'==ch)
            {
                if(++cntA > 1) return false;//
                cntL = 0;//
            }
            else if('L' == ch)
            {
                if(++cntL > 2) return false;//
            }
            else cntL = 0;//
        }
        return true;
    }
};

理解题意很简单,重要的是其中的逻辑怎么实现。还有一点需要注意自加自减运算,感觉还是有点不熟练。。

参考

1. Leetcode_easy_551. Student Attendance Record I;

2. Grandyang;

原文地址:https://www.cnblogs.com/happyamyhope/p/10947954.html