Simple C++ Solution


  • 0
    F
    class Solution {
    public:
        bool checkRecord(string s) {
            int countA = 0, maxL = 0, currL = 0;
            for (int i = 0; i < s.size(); i++) {
                if (s[i] == 'A') {
                    countA++;
                    currL = 0;
                } else if (s[i] == 'L') {
                    currL++;
                    maxL = max(maxL, currL);
                } else {
                    currL = 0;
                }
                if (countA > 1 || maxL > 2)
                    return false;
            }
            return true;
        }
    }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.