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;
    }
};
相关推荐
sin_hielo20 小时前
leetcode 2110
数据结构·算法·leetcode
獭.獭.20 小时前
C++ -- STL【unordered_set和unordered_map的使用】
c++·stl·unordered_map·unordered_set
麦格芬23021 小时前
LeetCode 763 划分字母区间
算法·leetcode·职场和发展
star _chen21 小时前
C++ std::move()详解:从小白到高手
开发语言·c++
福尔摩斯张21 小时前
C++核心特性精讲:从C语言痛点出发,掌握现代C++编程精髓(超详细)
java·linux·c语言·数据结构·c++·驱动开发·算法
charlie1145141911 天前
如何快速在 VS2026 上使用 C++ 模块 — 完整上手指南
开发语言·c++·笔记·学习·现代c++
报错小能手1 天前
STL_unordered_map
开发语言·c++·哈希算法
月明长歌1 天前
【码道初阶】【LeetCode 110】平衡二叉树:如何用一个“Magic Number”将复杂度从O(N²)降为 O(N)?
linux·算法·leetcode
yaoh.wang1 天前
力扣(LeetCode) 14: 最长公共前缀 - 解法思路
python·程序人生·算法·leetcode·面试·职场和发展·跳槽
历程里程碑1 天前
C++ 9 stack_queue:数据结构的核心奥秘
java·开发语言·数据结构·c++·windows·笔记·算法