551 Student Attendance Record I 学生出勤纪录 I
给定一个字符串来代表一个学生的出勤纪录,这个纪录仅包含以下三个字符:
'A' : Absent,缺勤
'L' : Late,迟到
'P' : Present,到场
如果一个学生的出勤纪录中不超过一个'A'(缺勤)并且不超过两个连续的'L'(迟到),那么这个学生会被奖赏。
你需要根据这个学生的出勤纪录判断他是否会被奖赏。
示例 1:
输入: "PPALLP"
输出: True
示例 2:
输入: "PPALLL"
输出: False
详见:https://leetcode.com/problems/student-attendance-record-i/description/
C++:
方法一:
class Solution {
public:
bool checkRecord(string s)
{
int cntA = 0, cntL = 0;
for (char c : s)
{
if (c == 'A')
{
if (++cntA > 1)
{
return false;
}
cntL = 0;
}
else if (c == 'L')
{
if (++cntL > 2)
{
return false;
}
}
else
{
cntL = 0;
}
}
return true;
}
};
方法二:
class Solution {
public:
bool checkRecord(string s)
{
return (s.find("A") == string::npos || s.find("A") == s.rfind("A")) && s.find("LLL") == string::npos;
}
};
参考:http://www.cnblogs.com/grandyang/p/6736484.html
551 Student Attendance Record I 学生出勤纪录 I的更多相关文章
- 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] 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, whic ...
- [LeetCode] Student Attendance Record I 学生出勤记录之一
You are given a string representing an attendance record for a student. The record only contains the ...
- Leetcode551.Student Attendance Record I学生出勤记录1
给定一个字符串来代表一个学生的出勤纪录,这个纪录仅包含以下三个字符: 'A' : Absent,缺勤 'L' : Late,迟到 'P' : Present,到场 如果一个学生的出勤纪录中不超过一个' ...
- 552 Student Attendance Record II 学生出勤记录 II
给定一个正整数 n,返回长度为 n 的所有可被视为可奖励的出勤记录的数量. 答案可能非常大,你只需返回结果mod 109 + 7的值.学生出勤记录是只包含以下三个字符的字符串: 1.'A' : ...
- 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 ...
- 551. Student Attendance Record I 从字符串判断学生考勤
[抄题]: You are given a string representing an attendance record for a student. The record only contai ...
随机推荐
- selenium使用笔记(一)——selenium你该知道的
有时候在交流群里经常会看到这样的问题,selenium能进行性能测试吗?selenium1和selenium2有什么区别等等问题,在这里谈一下自己学习和工作以后对selenium的认识.我所记录的东西 ...
- .net2.0 C# Json反序列化
http://cjl20082002.blog.163.com/blog/static/120827332009511103457637/ 去:http://json.codeplex.com/下载 ...
- mysql general log开启
#先查看当前状态 mysql> show variables like 'general%'; +------------------+----------------------------- ...
- elasticsearch function_score Query——文档排序结果的最后一道墙
function_score Query The function_score query is the ultimate tool for taking control of the scoring ...
- python 复制文件流程
例子代码: [root@master script]# vim copy_file.py #!/usr/bin/python # -*- coding:utf-8 -*- old_file_name ...
- python 基础之第十一天(面向对象)
#############面向对象##################### 类: In [1]: class MyClass(object): ##用class定义一个类 ...: def psta ...
- HDU2159(完全背包)
FATE Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Description ...
- Array 对象
Array的对象用于在单个的变量中存储多个值. constructor 返回对创建此对象的数组函数的引用. demo: let arr=[]; arr.constructor==Array let ...
- staruml详解
一.用例图 1.说明 1.1 用例图说明的事谁要使用系统以及他们使用该系统可以做些什么? <业务需求> 1.2 解析一个用例图,我们可以发现它包含4个 ...
- 堆栈(栈stack)的实现和基本用法(二)
个人网站http://www.ravedonut.com/ 栈的应用: #include <iostream> #include <stack> using namespace ...