LeetCode 551. Student Attendance Record I (C++)
题目:
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
分析:
给定一个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++)的更多相关文章
- LeetCode 551. Student Attendance Record I (学生出勤纪录 I)
You are given a string representing an attendance record for a student. The record only contains the ...
- 551. Student Attendance Record I【easy】
551. Student Attendance Record I[easy] You are given a string representing an attendance record for ...
- 【leetcode_easy】551. Student Attendance Record I
problem 551. Student Attendance Record I 题意: solution: class Solution { public: bool checkRecord(str ...
- [LeetCode] 552. Student Attendance Record II 学生出勤记录之二
Given a positive integer n, return the number of all possible attendance records with length n, whic ...
- 551. Student Attendance Record I 从字符串判断学生考勤
[抄题]: You are given a string representing an attendance record for a student. The record only contai ...
- 【LeetCode】551. Student Attendance Record I 解题报告(Java & Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 正则表达式 统计 日期 题目地址:https://l ...
- [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 ...
- 551. Student Attendance Record I + Student Attendance Record II
▶ 一个学生的考勤状况是一个字符串,其中各字符的含义是:A 缺勤,L 迟到,P 正常.如果一个学生考勤状况中 A 不超过一个,且没有连续两个 L(L 可以有多个,但是不能连续),则称该学生达标(原文表 ...
- leetCode题解 Student Attendance Record I
1.题目描述 You are given a string representing an attendance record for a student. The record only conta ...
随机推荐
- 四、 git关联远程仓库及推送
接之前笔记,在 github上建立与本地同名的仓库 demo 关联远程仓库 1. https 模式 远程库的名字就是origin,这是Git默认的叫法 git remote add origi ...
- Swift Package Manager(一)初探
一句话:Swift Package Manager(swift包管理器,简称:SPM)就是在swift开发中用来替代CocoaPod的:在swift开发中,SPM完全可以替代CocoaPod的功能,并 ...
- Android设置常见控件点击效果
一. Imageview的点击效果——图片稍微变暗突出点击效果 public class ClickImageView extends AppCompatImageView { public Clic ...
- apache配置文件:http.conf配置详解
Apache的配置文件http.conf参数含义详解 Apache的配置由httpd.conf文件配置,因此下面的配置指令都是在httpd.conf文件中修改.主站点的配置(基本配置) (1) 基本配 ...
- M100(3) 无线数传
本文记录了无线数传配合地面Windos qt写的飞机控制SDK软件的使用过程 使用了两种类型无线数传 遇到问题 1 界面卡死问题 1.1 数传问题 问题描述: 使用非官方数传,点击active按键和一 ...
- 环境搭建(Python)
Python 开发环境搭建 Windows篇 一. Python安装 资源获取 登录Python官网的Windows下载页面https://www.python.org/downloads/win ...
- 关于javascript中对浮点加,减,乘,除的精度分析
大学专业是计算机童鞋或多或小的知道 计算机是由二进制存储和处理数字的,不能精确到处理浮点数,且javascript也没有这样的方法 所以在浏览器计算的时候也会有误差,比如说 我想用 3.3 / 1.1 ...
- DQN(Deep Reiforcement Learning) 发展历程(五)
目录 值函数的近似 DQN Nature DQN DDQN Prioritized Replay DQN Dueling DQN 参考 DQN发展历程(一) DQN发展历程(二) DQN发展历程(三) ...
- http_build_query用法,挺方便的
http_build_query (PHP 5) http_build_query -- 生成 url-encoded 之后的请求字符串描述string http_build_query ( arra ...
- activiti发布APP时报错:关联的流程无效
解决办法: 1.检查流程命名和任务命名以及其他命名中是否有特殊字符,有一些字符是不支持的.(中文是可以的,中文标点符号可能不行,我的经验是顿号会报错) 2.检查流程图,把鼠标放到每一根连接线上,观察它 ...