leetCode题解 Student Attendance Record I
1、题目描述
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’返回false。 2、代码
bool checkRecord(string s) {
int numA = ;
int numL = ;
for(int i = ; i < s.size(); i++)
{
if(s[i] == 'A' && ++numA > )
return false;
if(s[i] == 'L')
{
numL++;
if(numL > )
return false;
}
else
numL = ;
}
return true;
}
leetCode题解 Student Attendance Record I的更多相关文章
- [LeetCode] 552. Student Attendance Record II 学生出勤记录之二
Given a positive integer n, return the number of all possible attendance records with length n, whic ...
- LeetCode 551. Student Attendance Record I (学生出勤纪录 I)
You are given a string representing an attendance record for a student. The record only contains the ...
- LeetCode 551. Student Attendance Record I (C++)
题目: You are given a string representing an attendance record for a student. The record only contains ...
- [LeetCode] Student Attendance Record II 学生出勤记录之二
Given a positive integer n, return the number of all possible attendance records with length n, whic ...
- 【leetcode】552. Student Attendance Record II
题目如下: Given a positive integer n, return the number of all possible attendance records with length n ...
- [Swift]LeetCode552. 学生出勤记录 II | Student Attendance Record II
Given a positive integer n, return the number of all possible attendance records with length n, whic ...
- 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 ...
- 551. Student Attendance Record I【easy】
551. Student Attendance Record I[easy] You are given a string representing an attendance record for ...
随机推荐
- phpdocumentor生成代码注释文档(linux)
1,默认安装lnmp环境(php7),默认pear安装 2, pear channel-discover pear.phpdoc.org pear install phpdoc/phpDocume ...
- 安装Elasticsearch5.0 部署Head插件
部署5.0版本的ES 5.0版本的ES跟之前的版本最大的不同之处就是多了很多环境的校验,比如jdk,max-files等等. 设置内核参数 vi /etc/sysctl.conf # 增加下面的内容 ...
- Oracle11g常用数据字典
转:https://blog.csdn.net/fulq1234/article/details/79760698 Oracle数据字典的名称由前缀和后缀组成,使用_连接,含义说明如下: dba_:包 ...
- Android 开发工具类 03_HttpUtils
Http 请求的工具类: 1.异步的 Get 请求: 2.异步的 Post 请求: 3.Get 请求,获得返回数据: 4.向指定 URL 发送 POST方法的请求. import java.io.Bu ...
- java-TreeSet进行排序的2种方式
TreeSet和HashSet的区别在于, TreeSet可以进行排序, 默认使用字典顺序排序, 也可以进行自定义排序 1, 自然排序 2, 比较器排序 自然排序: 1, 需要被排序的类实现Compa ...
- WPF中定义TabItem的可选区域(特别是当使用Label来呈现Header时)
1. 如上图,所示,此时当鼠标移入蓝色框内除文字部分,整个TabItem是没反应的 经过查看代码可以看到: 将图标中的VerticalAlignment="Center"和Hori ...
- C++中指针和引用、数组之间的区别
指针指向一块内存,它的内容是所指内存的地址:而引用则是某块内存的别名,引用初始化后不能改变指向.使用时,引用更加安全,指针更加灵活. 初始化.引用必须初始化,且初始化之后不能呢改变:指针可以不必初始化 ...
- Major GC和Full GC的区别是什么?触发条件呢?
作者:RednaxelaFX链接:http://www.zhihu.com/question/41922036/answer/93079526来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非 ...
- C#基础知识回顾--BackgroundWorker介绍
简介 BackgroundWorker是.net里用来执行多线程任务的控件,它允许编程者在一个单独的线程上执行一些操作.耗时的操作(如下载和数据库事务)在长时间运行时可能会导致用户界面 (UI) 始终 ...
- 用bind方法保持this上下文
什么是this对象 先来说说什么是this对象吧.每一个函数在调用的时候都会自己主动获取两个特殊变量:this和arguments对象. this值详细是指哪个对象是和该函数的运行环境相关的.假设是作 ...