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 ...
随机推荐
- javascript,object,IDispatchEx笔记
//js: var testObj=new Object; //com内部: testObj=Object::InvokeEx(wFlags==DISPATCH_CONSTRUCT); //注: // ...
- October 11th 2017 Week 41st Wednesday
If you don't know where you are going, you might not get there. 如果你不知道自己要去哪里,你可能永远到不了那里. The reward ...
- 【Alpha go】Day 2!
[Alpha go]Day 2! Part 0 · 简要目录 Part 1 · 项目燃尽图 Part 2 · 项目进展 Part 3 · 站立式会议照片 Part 4 · Scrum 摘要 Part ...
- Java的数组堆溢出问题
在写测试方法的时候,生成了一个数组,之后报了堆溢出错误,这样的报错一般来说只要有一些JVM的基础都知道要用-Xmx.-Xms来开更大的堆,接下来看看我碰到的一个堆溢出的问题 在测试代码中开了一个500 ...
- swift语言的特征:类型系统与函数式编程:swift是面向类型和面向函数编程的语言
swift语言的特征: 类型系统:值类型与引用类型.泛型.协议类型 函数式编程:
- 【Hibernate步步为营】--核心对象+持久对象全析(一)
引言 上篇博客对Hibernate进行了基本的解析.并分析了它的一些特性. Hibernate可以如此的流行也是由于它有诸多长处,不论什么事物都有两面性.Hibernate尽管流行.可 ...
- single number和变体
给array of integers. 裡面有一个数字是单独出现 其他都会出现两次(而且一起出现)ex: [1,2,2,3,3]要判断哪个数字是单独出现的. 以这个例子的话就是 1 LZ 一开始先说 ...
- Failed to load or instantiate TagLibraryValidator class: org.apache.taglibs
在部署工程时,没有加入javax.servlet-api.jar(3.0.1) 和 standard.jar(1.1.2)两个jar包导致此问题. 另外,如果原来容器中有javax.servlet-a ...
- Linux下jdk&tomcat的安装
unbantu: 1.下载相应版本的jdk及tomcat:sudo wget ${url} 2.解压: tar zxvf jdk-7u79-linux-x64.tar.gz tar zxvf apa ...
- websocket python实现原理
""" pip install ws4py """ import json from ws4py.client.threadedclient ...