C++, simple, no redundancy


  • 0
    M
    bool checkRecord(string s) {
        size_t count_a = 0, count_l = 0;
        for (const auto& i : s) {
            if (i != 'L') {
                count_l = 0;
                if (i == 'A') {
                    ++count_a;
                }
            } else {
                ++count_l;
            }
            if (count_a > 1 || count_l > 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.