Student Attendance Record I
来源:互联网 发布:centos如何安装rpm包 编辑:程序博客网 时间:2024/06/01 07:11
Student Attendance Record I
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解析:求absent的个数,和最大连续late的个数,若absent大于1,或者最大连续late大于2返回false
代码:
class Solution {public: bool checkRecord(string s) { int abnum=0; int latenum=0; int lastnum=0; for (int i=0; i<s.size(); i++) { if (s[i]=='A') { abnum++; lastnum=max(lastnum,latenum); latenum=0; } else if (s[i]=='L') { latenum++; } else { lastnum=max(lastnum,latenum); latenum=0; } } lastnum=max(lastnum,latenum); if (abnum>1||lastnum>2) return false; return true; }};
0 0
- Student Attendance Record I
- Student Attendance Record I
- Student Attendance Record I
- 551. Student Attendance Record I
- leetcode551: Student Attendance Record I
- 551. Student Attendance Record I
- 551. Student Attendance Record I
- 551. Student Attendance Record I
- 551. Student Attendance Record I
- 551. Student Attendance Record I
- leetcode551. Student Attendance Record I
- 551. Student Attendance Record I
- 551. Student Attendance Record I
- 551. Student Attendance Record I
- 551. Student Attendance Record I
- 551. Student Attendance Record I
- 551. Student Attendance Record I
- LeetCode 551. Student Attendance Record I
- Linux系统下安装Adobe Flash Player插件的方法
- 大端模式和小端模式
- CGLIB(Code Generation Library)详解
- Brillo和Weave
- 170418 汇编-adc和sbb的进位/借位加减法命令
- Student Attendance Record I
- 【老板来了你立刻知道!】人脸识别+手机推送
- 运行tomcat Server报以下错误
- Haar特征与积分图
- 2017省选拔 (二)poj3169 Layout (差分约束)
- ionic2点击事件感觉到延迟的解决办法
- 二叉搜索树的后序遍历序列
- redis学习记录06-pipeline
- maven安装与配置