技术栈

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

Ddddddd_1582024-11-10 16:14

题目:

题解:

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;
    }
};
上一篇:Linux应用——线程池
下一篇:python实现各种描述统计/概率分布/假设检验/置信区间/回归/方差分析/卡方检验
相关推荐
saltymilk
1 天前
C++ 模板参数推导问题小记(模板类的模板构造函数)
c++·模板元编程
感哥
1 天前
C++ lambda 匿名函数
c++
沐怡旸
1 天前
【底层机制】std::unique_ptr 解决的痛点?是什么?如何实现?怎么正确使用?
c++·面试
感哥
1 天前
C++ 内存管理
c++
博笙困了
2 天前
AcWing学习——双指针算法
c++·算法
感哥
2 天前
C++ 指针和引用
c++
感哥
2 天前
C++ 多态
c++
沐怡旸
2 天前
【底层机制】std::string 解决的痛点?是什么?怎么实现的?怎么正确用?
c++·面试
River416
2 天前
Javer 学 c++(十三):引用篇
c++·后端
感哥
3 天前
C++ std::set
c++
热门推荐
01GitHub 镜像站点02UV 工具安装与国内镜像源配置指南0346个Nano-banana 精选提示词,持续更新中04Claude Code 平替:OpenAI发布 Codex CLI ,GPT-5 国内直接使用05UV安装并设置国内源06保姆级教程:手把手教你用Dify实现完美多轮对话(附Chatflow和提示词)07A股预测还能更准?开源大模型Kronos带你跑通预测+回测全流程08Spec-Kit 使用指南09解决 WSL Ubuntu 中 /etc/resolv.conf 自动重置问题10KGG转MP3工具|非KGM文件|解密音频