题目:

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

  1. 'A' : Absent.
  2. 'L' : Late.
  3. '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

分析:

给定一个string,其中包含A,L,P,如果多于1个A,或者多于连续2个L则返回False,否则返回True。

我们定义Lcnums表示L连续的数量,Anums表示A的数量,对给定的s遍历。

首先判断字符是不是A,如果是则Anums加1,否则什么都不做。继续判断这个字符是不是L,如果是则Lcnums加1,否则将Lcunms清零,注意遍历的时候只要字符不是L都要将Lcnums清零,然后判断Lcnums和Anums的数量是否符合要求即可。

程序:

class Solution {
public:
bool checkRecord(string s) {
int Lcnums = ;
int Anums = ;
for(auto i:s){
if(i == 'A') Anums++;
if(i == 'L'){
Lcnums++;
}
else
Lcnums = ;
if(Anums == ||Lcnums == ){
return false;
}
}
return true;
}
};

LeetCode 551. Student Attendance Record I (C++)的更多相关文章

  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. 551. Student Attendance Record I【easy】

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

  3. 【leetcode_easy】551. Student Attendance Record I

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

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

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

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

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

  6. 【LeetCode】551. Student Attendance Record I 解题报告(Java & Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 正则表达式 统计 日期 题目地址:https://l ...

  7. [LeetCode&Python] Problem 551. Student Attendance Record I

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

  8. 551. Student Attendance Record I + Student Attendance Record II

    ▶ 一个学生的考勤状况是一个字符串,其中各字符的含义是:A 缺勤,L 迟到,P 正常.如果一个学生考勤状况中 A 不超过一个,且没有连续两个 L(L 可以有多个,但是不能连续),则称该学生达标(原文表 ...

  9. leetCode题解 Student Attendance Record I

    1.题目描述 You are given a string representing an attendance record for a student. The record only conta ...

随机推荐

  1. 团队作业8--测试与发布(Beta阶段)

    展示博客 一.项目成员: 张慧敏(组长)201421122032 苏晓薇(组员)201421031033 欧阳时康(组员)201421122050 团队仓库: https://git.coding.n ...

  2. Phoenix安装配置

    下载Phoenix     在网站http://phoenix.apache.org/download.html找到对应HBase版本的安装程序,并下载安装包,解压安装程序到指定目录 [root@ha ...

  3. 9.Solr4.10.3数据导入(post.jar方式和curl方式)

    转载请出自出处:http://www.cnblogs.com/hd3013779515/ 1.使用post.jar方式 java -Durl=http://192.168.137.168:8080/s ...

  4. CGJ02、BD09、西安80、北京54、CGCS2000常用坐标系详解

    一.万能地图下载器中的常用坐标系 水经注万能地图下载器中的常用的坐标系主要包括WGS84经纬度投影.WGS84 Web 墨卡托投影.WGS84 UTM 投影.北京54高斯投影.西安80高斯投影.CGC ...

  5. Oracle_spatial的空间索引

    空间索引 1.空间索引的创建 1)创建索引之前总是要为空间层插入元数据 2)如果之前创建的索引失败了,必须先删除才能创建 Drop index customers_sidx; 创建索引: Create ...

  6. Guava 的EventBus示例代码(简单笔记,后期补充)

    package guavademo.event.bus; import com.google.common.eventbus.EventBus; import com.google.common.ev ...

  7. Ant在MyEclipse中的配置总结

    1.在配置Ant之前,先要配置好JDK的JAVA_HOME和path:之后下载解压apache-ant-1.7.1;并配置环境变量ANT_HOME(安装目录,后不可以加分号:)及其path(安装目录/ ...

  8. 织梦提交表单(提交留言)前的js校验

    第一种情况:页面有引入jq的 在form标签上加上id <form action="/plus/diy.php" enctype="multipart/form-d ...

  9. js基础知识整理

    一.javaScript,也称之为js,是专为网页交互设计的脚本语言.主要由以下三部分组成: 1)ECMAScript  由ECMA-262定义,提供核心语言功能. 2)DOM对象(document ...

  10. python获取文件扩展名的方法(转)

    主要介绍了python获取文件扩展名的方法,涉及Python针对文件路径的相关操作技巧.具体实现方法如下: 1 2 3 4 import os.path def file_extension(path ...