题目:

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. PyQt5--GridLayoutMultiLine

    # -*- coding:utf-8 -*- ''' Created on Sep 13, 2018 @author: SaShuangYiBing ''' import sys from PyQt5 ...

  2. JSONP跨域和CORS跨域

    什么是跨域? 跨域:指的是浏览器不能执行其它网站的脚本,它是由浏览器的同源策略造成的,是浏览器的安全限制! 同源策略 同源策略:域名.协议.端口均相同. 浏览器执行JavaScript脚本时,会检查这 ...

  3. BZOJ2115:[WC2011] Xor(线性基)

    Description Input 第一行包含两个整数N和 M, 表示该无向图中点的数目与边的数目. 接下来M 行描述 M 条边,每行三个整数Si,Ti ,Di,表示 Si 与Ti之间存在 一条权值为 ...

  4. mpvue 使用echarts动态绘制图表(数据改变重新渲染图表)

    最近在公司开发一款微信小程序,按照客户需求用饼状图显示当前设备状态(开机.故障.关机),于是就在网上寻找各种资料,找了很多mpvue使用关于echarts绘制图表,最终功夫不负有心人,找到一篇关于mp ...

  5. kvm安装配置使用centos6.5

    # yum -y install kvm virt-* libvirt  && yum -y groupinstall Virtualization 'Virtualization C ...

  6. js_script

    使用 self.crawl 的 js_script 参数,在页面上执行一段脚本,实现[点击加载更多]的效果: def on_start(self): self.crawl('http://movie. ...

  7. js基础知识入门总结

    1.第一个js程序 一个项目包括三部分:前端(html.css.js).数据库.后端技术 引入方式:页面中直接写,script标签引入 js事件绑定: <input type="but ...

  8. C++之友元函数和友元类

    通过friend关键字,我们可以将不属于当前类的一个函数在当前类中加以声明,该函数便可以成为当前类的友元函数. #include<iostream>using namespace std; ...

  9. Java设置以及获取JavaBean私有属性进阶

    在上一篇博客中讲到使用Java提供的原生API设置以及获取一个JavaBean的私有属性. 但是使用Java的原生API过于复杂,有没有更加简单的方法呢?答案是肯定的.下面介绍一个开元工具包来非常方便 ...

  10. ubuntu14.04安装jupyter notebook

    1.使用pip安装Jupyter notebook: pip install jupyter notebook 2.创建Jupyter默认配置文件: jupyter notebook --genera ...