给定一个字符串来代表一个学生的出勤纪录,这个纪录仅包含以下三个字符:
    '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. 2U网络机箱的尺寸是多少,4U网络机箱的尺寸是多少

    厚度以4.445cm为基本单位.1U就是4.445cm,2U则是1U的2倍为8.89cm.48.26cm=19英寸,如果是标准的机架式设备,宽应该是满足这个标准的.纵深的话 有600mm或者800mm ...

  2. python不同目录下的调用

    转自http://blog.csdn.net/hansel/article/details/8975663 Python包含子目录中的模块方法比较简单,关键是能够在sys.path里面找到通向模块文件 ...

  3. swoole_http_server客户端测试

    测试方法: http_server.php 文件内容 <?php // use Swoole\Http\Server; // $http = new Server("0.0.0.0&q ...

  4. emacs设置tab缩进

    这两天使用Emacs自带的JavaScriptMode时,发现与其它编辑器下缩进不同,而且用emacs重新缩进对齐后,再用其它的编辑器打时缩进却乱掉了.分析应该是Tab缩进的问题,在.emacs中增加 ...

  5. JNI之JAVA调用C++接口

    1.JNI定义(来自百度百科) JNI是Java Native Interface的缩写,中文为JAVA本地调用.从Java1.1开始,Java Native Interface(JNI)标准成为ja ...

  6. QQ登陆功能的实现2

    QQ登陆功能的实现2 由于看到园子里有朋友说需要讲解和剖析实现的步骤,前面的QQ登陆实现只有代码,所以这篇补上 1.  分析 1). 当运行QQ.exe后会出现qq登陆界面的窗体 2). 我们用spy ...

  7. PHP正则匹配中文汉字注意

    preg_match('/^[a-zA-Z\x{4e00}-\x{9fa5}]+$/u', $str) 如上,是匹配字母或者汉字的,一定要在后面加模式修饰符 u , 不然就出错! u (PCRE_UT ...

  8. Codeforces 1108F MST Unification MST + LCA

    Codeforces 1108F MST + LCA F. MST Unification Description: You are given an undirected weighted conn ...

  9. rpm 命令|rpm 安装|rpm 卸载|rpm 使用|rpm 删除

    在Linux操作系统中,有一个系统软件包,它的功能类似于Windows里面的“添加/删除程序”,但是功能又比“添加/删除程序”强很多,它就是Red Hat Package Manager(简称RPM) ...

  10. python 之队列

    进程和线程模块下都有队列类. 线程队列: # 后进先出->堆栈 q=queue.LifoQueue(3) # 优先级队列,数字越小优先级越高 q=queue.PriorityQueue(3) 进 ...