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 ...
随机推荐
- VS2008 开发wince程序设备调试
今天之前开发的一个wince程序,用户反馈报错,由于很久没玩了,从用户那里拿来设备.结果怎么调试的忘记了.在网上找了些资料,自己有摸索了一下.才搞定. 1.安装Microsoft ActiveSync ...
- sql点滴44—mysql忘记root密码
1. 首先检查mysql服务是否启动,若已启动则先将其停止服务,可在开始菜单的运行,使用命令: net stop mysql 打开第一个cmd1窗口,切换到mysql的bin目录,运行命令: mysq ...
- Mojave使用pyenv安装python-zlib错误
mojave使用pyenv编译python出现 zipimport.ZipImportError: can't decompress data; zlib not available错误 解决方案: ...
- 阿里八八Alpha阶段Scrum(11/12)
今日进度 叶文滔: 合并日程界面debug成功,但是目前出现了新的问题,日程界面一些控件无法适配屏幕,正在排查问题 李嘉群: 尝试用okhttp的方式发送请求 王国超: 今天开始进行recycerli ...
- 一些node模块的学习思考
12月14日清单 1 readline模块 var readline = require("readline"); // input 是必须的,output是可选的 rl = re ...
- php的匿名函数和闭包函数
php的匿名函数和闭包函数 tags: 匿名函数 闭包函数 php闭包函数 php匿名函数 function use 引言:匿名函数和闭包函数都不是特别高深的知识,但是很多刚入门的朋友却总是很困惑,因 ...
- JAVA框架 Spring 调用jdbcsuport简化开发
一)使用DAO的jdbcsuport来简化开发 首先来清楚一个概念: 我们在进行配置文件来进行依赖注入的时候,主要是通过set方法来进行设置的. 正常我们使用spring的jdbctemplate的时 ...
- 2.2《想成为黑客,不知道这些命令行可不行》(Learn Enough Command Line to Be Dangerous)——列表
也许最常用的Unix命令是ls了,它是'list'的简写(Listing 8) Listing 8 用ls以列表的形式显示文件和目录(内容输出跟各自电脑有关) $ ls Desktop Downloa ...
- ajax入门简述
ajax 全称为 “Asynchronous JavaScript and XML”(异步 JavaScript 和 XML),是一种创建交互式网页应用的网页开发技术,本质上是一个浏览器端的技术,就是 ...
- 20155229《网络对抗技术》Exp9:Web安全基础
实验内容 Webgoat实践下相关实验. 实验步骤 WebGoat: Webgoat是OWASP组织研究出的一个专门进行web漏洞实验的应用品台,这个平台里包含了web中常见的各种漏洞,例如:跨站脚本 ...