C++ | Leetcode C++题解之第551题学生出勤记录I

题目:

题解:

cpp 复制代码
class Solution {
public:
    bool checkRecord(string s) {
        int absents = 0, lates = 0;
        for (auto &ch : s) {
            if (ch == 'A') {
                absents++;
                if (absents >= 2) {
                    return false;
                }
            }
            if (ch == 'L') {
                lates++;
                if (lates >= 3) {
                    return false;
                }
            } else {
                lates = 0;
            }
        }
        return true;
    }
};
相关推荐
JANYI20183 小时前
C文件在C++平台编译时的注意事项
java·c语言·c++
freyazzr4 小时前
Leetcode刷题 | Day51_图论03_岛屿问题02
数据结构·c++·算法·leetcode·深度优先·图论
2301_807611494 小时前
126. 单词接龙 II
c++·算法·leetcode·深度优先·广度优先·回溯
奋进的小暄6 小时前
数据结构(4) 堆
java·数据结构·c++·python·算法
feiyangqingyun6 小时前
Qt/C++源码/实时视音频通话示例/极低延迟/可外网通话/画中画/支持嵌入式板子
c++·qt·qt视音频通话
珊瑚里的鱼6 小时前
LeetCode 102题解 | 二叉树的层序遍历
开发语言·c++·笔记·算法·leetcode·职场和发展·stl
Wabi_sabi_x7 小时前
C++设计模式:面向对象的八大设计原则之一
开发语言·c++·设计模式
阳洞洞7 小时前
leetcode 59. 螺旋矩阵 II
leetcode·矩阵
xiaolang_8616_wjl7 小时前
c++_2011 NOIP 普及组 (1)
开发语言·数据结构·c++·算法·c++20
Demons_kirit8 小时前
LeetCode 1007. 行相等的最少多米诺旋转 题解
算法·leetcode·职场和发展