LeetCode 551. Student Attendance Record I (C++)
题目:
You are given a string representing an attendance record for a student. The record only contains the following three characters:
- 'A' : Absent.
- 'L' : Late.
- 'P' : Present.
A student could be rewarded if his attendance record doesn't contain more than one 'A' (absent) or more than two continuous 'L' (late).
You need to return whether the student could be rewarded according to his attendance record.
Example 1:
Input: "PPALLP"
Output: True
Example 2:
Input: "PPALLL"
Output: False
分析:
给定一个string,其中包含A,L,P,如果多于1个A,或者多于连续2个L则返回False,否则返回True。
我们定义Lcnums表示L连续的数量,Anums表示A的数量,对给定的s遍历。
首先判断字符是不是A,如果是则Anums加1,否则什么都不做。继续判断这个字符是不是L,如果是则Lcnums加1,否则将Lcunms清零,注意遍历的时候只要字符不是L都要将Lcnums清零,然后判断Lcnums和Anums的数量是否符合要求即可。
程序:
class Solution {
public:
bool checkRecord(string s) {
int Lcnums = ;
int Anums = ;
for(auto i:s){
if(i == 'A') Anums++;
if(i == 'L'){
Lcnums++;
}
else
Lcnums = ;
if(Anums == ||Lcnums == ){
return false;
}
}
return true;
}
};
LeetCode 551. Student Attendance Record I (C++)的更多相关文章
- LeetCode 551. Student Attendance Record I (学生出勤纪录 I)
You are given a string representing an attendance record for a student. The record only contains the ...
- 551. Student Attendance Record I【easy】
551. Student Attendance Record I[easy] You are given a string representing an attendance record for ...
- 【leetcode_easy】551. Student Attendance Record I
problem 551. Student Attendance Record I 题意: solution: class Solution { public: bool checkRecord(str ...
- [LeetCode] 552. Student Attendance Record II 学生出勤记录之二
Given a positive integer n, return the number of all possible attendance records with length n, whic ...
- 551. Student Attendance Record I 从字符串判断学生考勤
[抄题]: You are given a string representing an attendance record for a student. The record only contai ...
- 【LeetCode】551. Student Attendance Record I 解题报告(Java & Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 正则表达式 统计 日期 题目地址:https://l ...
- [LeetCode&Python] Problem 551. Student Attendance Record I
You are given a string representing an attendance record for a student. The record only contains the ...
- 551. Student Attendance Record I + Student Attendance Record II
▶ 一个学生的考勤状况是一个字符串,其中各字符的含义是:A 缺勤,L 迟到,P 正常.如果一个学生考勤状况中 A 不超过一个,且没有连续两个 L(L 可以有多个,但是不能连续),则称该学生达标(原文表 ...
- leetCode题解 Student Attendance Record I
1.题目描述 You are given a string representing an attendance record for a student. The record only conta ...
随机推荐
- October 31st, 2017 Week 44th Tuesday
No matter how hard the past is, you can always begin again. 不管过去有多么困难,你都可以重新开始. Honestly, I don't ag ...
- 团队作业——Alpha冲刺 8/12
团队作业--Alpha冲刺 冲刺任务安排 杨光海天 今日任务:将编辑界面与其中字体设置的弹窗合并,学习Android控件交互. 明日任务:希望完成编辑界面所有接口交互的功能. 郭剑南 今日任务:使用P ...
- A “Type Erasure” Pattern that Works in Swift:类型域的转换
新视角:通过函数式编程的范畴理论来看待这个问题会更容易理解: 在低层类型无法很好表达的类型,可以将其转化为高阶类型进行表示. 将协议的实现类型转化为monad类型: 解决将具有关联类型的协议当作类型的 ...
- Codeforces Round #503 Div. 2
时间相对来说还是比较合适的,正好放假就可以打一打啦. A. New Building for SIS:http://codeforces.com/contest/1020/problem/A 题意概述 ...
- SDOI 2018 R2 游记
一篇真正的“游记”. DAY -3 下午: 今天老师批准了我去省选划水的请假要求. 批准之后感觉学习非常有动力,顺便忽悠别的同学和我一起去,然而wzx是唯一一个表示可以考虑一下的同学,其他同学直接一口 ...
- [JLOI2013]删除物品
嘟嘟嘟 只要每一次将优先级最高的上面的物品移走,就一定能保证是最优解. 所以我们只要想办法简化这个模拟移物品的过程,看完了题解后,发现可以这么想,我们可以把两个栈头碰头的挨在一起,然后设一个指针代表两 ...
- Unicode,GBK,GB2312,UTF-8概念基础(转载)
第一篇:JAVA字符编码系列一:Unicode,GBK,GB2312,UTF-8概念基础本部分采用重用,转载一篇文章来完成这部分的目标.来源:holen'blog 对字符编码与Unicode,IS ...
- Jmeter性能测试-分布式压力测试
作为一个测试行业的菜鸟,由于投身于一个小公司,包揽所有的测试.刚开始的功能测试到接口测试,稳定性测试,兼容性测试等,一般由于是小项目所以对于性能有所忽略,也没怎么涉及,公司接了个大项目,后期对于性能上 ...
- poj 3169 Layout(线性差分约束,spfa:跑最短路+判断负环)
Layout Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 15349 Accepted: 7379 Descripti ...
- kubernetes 资源请求和限制
1. spec: containers: - name: example resources: requests: ...