给定一个字符串来代表一个学生的出勤纪录,这个纪录仅包含以下三个字符:
    '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. haproxy官方配置文档地址

    http://cbonte.github.io/haproxy-dconv/1.6/configuration.html#4-option%20http-keep-alive

  2. Transaction事务注解和DynamicDataSource动态数据源切换问题解决

    问题描述: 写主库开事务的情况下会导致时不时的将更新/插入操作写入到从库上, 导致mysqlException update command denied   问题原因: jetty的工作队列会重用处 ...

  3. 多线程设计模式(一) Single Threaded Execution

    这里有一座独木桥.因为桥身非常的细,一次只能允许一个人通过.当这个人没有下桥,另一个人就不能过桥.如果桥上同时又两个人,桥就会因为无法承重而破碎而掉落河里. 这就是Single Threaded Ex ...

  4. python 快速排序 qsort

    def qsort(arr, start, end): if start > end: return def partition(arr, start, end): pivot = arr[st ...

  5. jQuery comet

    下面程序是例用从数据端推送信息,原理是每隔10秒读取一下data.txt文件,看有木有新的数据输入,如果有,则alert文件内容. hmtl代码是 <!DOCTYPE html> < ...

  6. 一:MetaMq集群中单个节点的安装配置示意图

    MetaMQ集群一个节点的安装和配置示意图[1]:下载metaMQ的安装包

  7. vue-cli脚手架搭建Vue.js项目

    前提条件: 一.node.js 下载 https://nodejs.org/zh-cn/download/ 二.webpack 安装 npm install webpack -g   PS:-g 就是 ...

  8. TFS独占签出代码

    最近发现微软给我们提供了免费的TFS,地址:http://tfs.visualstudio.com/, 就注册了一个,但是我发现没办法独占签出. 在公司里,TFS有服务端,所以很好设置,但是注册微软的 ...

  9. String类无子类

    1. 关于final修饰符 参考文章: 浅析Java中的final关键字 根据程序上下文环境,Java关键字final有“这是无法改变的”或者“终态的”含义,它可以修饰非抽象类.非抽象类成员方法和变量 ...

  10. jquery : eval() 解析json的注意

    jquery eval解析JSON中的注意点介绍 来在:http://www.jb51.net/article/40842.htm 在JS中将JSON的字符串解析成JSON数据格式,一般有两种方式: ...