给定一个字符串来代表一个学生的出勤纪录,这个纪录仅包含以下三个字符:
    '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的更多相关文章

  1. LeetCode 551. Student Attendance Record I (学生出勤纪录 I)

    You are given a string representing an attendance record for a student. The record only contains the ...

  2. [LeetCode] Student Attendance Record II 学生出勤记录之二

    Given a positive integer n, return the number of all possible attendance records with length n, whic ...

  3. [LeetCode] 552. Student Attendance Record II 学生出勤记录之二

    Given a positive integer n, return the number of all possible attendance records with length n, whic ...

  4. [LeetCode] Student Attendance Record I 学生出勤记录之一

    You are given a string representing an attendance record for a student. The record only contains the ...

  5. Leetcode551.Student Attendance Record I学生出勤记录1

    给定一个字符串来代表一个学生的出勤纪录,这个纪录仅包含以下三个字符: 'A' : Absent,缺勤 'L' : Late,迟到 'P' : Present,到场 如果一个学生的出勤纪录中不超过一个' ...

  6. 552 Student Attendance Record II 学生出勤记录 II

    给定一个正整数 n,返回长度为 n 的所有可被视为可奖励的出勤记录的数量. 答案可能非常大,你只需返回结果mod 109 + 7的值.学生出勤记录是只包含以下三个字符的字符串:    1.'A' : ...

  7. 551. Student Attendance Record I【easy】

    551. Student Attendance Record I[easy] You are given a string representing an attendance record for ...

  8. 【leetcode_easy】551. Student Attendance Record I

    problem 551. Student Attendance Record I 题意: solution: class Solution { public: bool checkRecord(str ...

  9. 551. Student Attendance Record I 从字符串判断学生考勤

    [抄题]: You are given a string representing an attendance record for a student. The record only contai ...

随机推荐

  1. 配置JDK和Tomcat环境变量(转)

    1.安装JDK 安装好JDK后,再配置JDK的环境变量:在“我的电脑”上点右键—>“属性”—>“高级”—> “环境变量(N)”. 新建系统变量JAVA_HOME:C:/Program ...

  2. Sports

    题目链接 : http://acm.hpu.edu.cn/problem.php?id=1184 或者       http://acm.nyist.net/JudgeOnline/problem.p ...

  3. <VS>MFC程序显示命令行窗口

    编写MFC程序时,想打印出调试信息,使用cout后,发现程序并没有像想象中那样自动弹出命令行窗口,要输出的信息也没地方去查看.百度后知道要手动调出命令行窗口,才可以看到输出的信息.   百度上介绍了两 ...

  4. BZOJ_2730_ [HNOI2012]矿场搭建_点双联通分量

    BZOJ_2730_ [HNOI2012]矿场搭建_点双联通分量 Description 煤矿工地可以看成是由隧道连接挖煤点组成的无向图.为安全起见,希望在工地发生事故时所有挖煤点的工人都能有一条出路 ...

  5. TX1 ssh配置

    执行: sudo apt-get install openssh-server 验证: sudo ps -e |grep ssh 回车-->有sshd,说明ssh服务已经启,如果没有则输入命令s ...

  6. TCP连接状态变化

    TCP连接状态变化 参考文章:TCP连接的状态详解以及故障排查 TCP建立连接--三次握手 CLOSED:起始状态,无任何连接. LISTEN:服务端建立socket之后需要listen进入LISTE ...

  7. JQuery扩展插件Validate—5添加自定义验证方法

    从前面的示例中不难看出validate中自带的验证方法足以满足一般的要求,对于特别的要求可以使用addMethod(name,method,message)添加自定义的验证规则,下面的示例中添加了一个 ...

  8. Beyond Compare 简体版+注册码

    Beyond Compare 3.3.4.14431 官方简体版+注册码 查阅全文 ›

  9. POJ - 3126 Prime Path 素数筛选+BFS

    Prime Path The ministers of the cabinet were quite upset by the message from the Chief of Security s ...

  10. [翻译] 正式宣布 .NET 5

    原文: Introducing .NET 5 今天,我们宣布 .NET Core 3.0 之后的下一个版本将是 .NET 5 .这将是 .NET 系列的下一个重要版本. 将来只会有一个 .NET ,您 ...