551. Student Attendance Record I【easy】
551. Student Attendance Record I【easy】
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
解法一:
class Solution {
public:
bool checkRecord(string s) {
int num_a = ; for (int i = ; i < s.length(); ++i) {
if (s[i] == 'A') {
if (++num_a > ) {
return false;
}
} if (i > && i < s.length() -
&& s[i] == 'L' && s[i - ] == 'L' && s[i + ] == 'L') {
return false;
}
} return true;
}
};
解法二:
public boolean checkRecord(String s) {
int countA=;
int continuosL = ;
int charA = 'A';
int charL ='L';
for(int i=;i<s.length();i++){
if(s.charAt(i) == charA){
countA++;
continuosL = ;
}
else if(s.charAt(i) == charL){
continuosL++;
}
else{
continuosL = ;
}
if(countA > || continuosL > ){
return false;
}
}
return true; }
参考@rakeshuky 的代码。
解法三:
public boolean checkRecord(String s) {
int acount=;
int lcount=;
for(char c : s.toCharArray()) {
if(c=='L') {
lcount++;
}
else {
lcount=;
if(c=='A') {
acount++;
}
}
if(acount> || lcount>=) {
return false;
}
}
return true;
}
参考@labs 的代码。
551. Student Attendance Record I【easy】的更多相关文章
- 【leetcode_easy】551. Student Attendance Record I
problem 551. Student Attendance Record I 题意: solution: class Solution { public: bool checkRecord(str ...
- 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 ...
- 551. Student Attendance Record I + Student Attendance Record II
▶ 一个学生的考勤状况是一个字符串,其中各字符的含义是:A 缺勤,L 迟到,P 正常.如果一个学生考勤状况中 A 不超过一个,且没有连续两个 L(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 ...
- LeetCode 551. Student Attendance Record I (C++)
题目: You are given a string representing an attendance record for a student. The record only contains ...
- 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
static int wing=[]() { std::ios::sync_with_stdio(false); cin.tie(NULL); ; }(); class Solution { publ ...
- 551 Student Attendance Record I 学生出勤纪录 I
给定一个字符串来代表一个学生的出勤纪录,这个纪录仅包含以下三个字符: 'A' : Absent,缺勤 'L' : Late,迟到 'P' : Present,到场如果一个学生的出勤纪 ...
随机推荐
- luogu P1291 [SHOI2002]百事世界杯之旅
题目链接 luogu P1291 [SHOI2002]百事世界杯之旅 题解 设\(f[k]\)表示还有\(k\)个球员没有收集到的概率 再买一瓶,买到的概率是\(k/n\),买不到的概率是\((n-k ...
- [Codeforces 32E] Hide-and-Seek
Brief Intro: 给两个人的坐标,一堵墙和一面镜子,询问两人能否看见对方 Solution: 一道以分类讨论为主的计算几何题, 分别讨论两人坐标连线是否经过墙/镜子即可, 难点在于如何求出点x ...
- 【权值分块】bzoj1208 [HNOI2004]宠物收养所
不多说.比pb_ds还是要快不少的. #include<cstdio> #include<algorithm> #include<cmath> using name ...
- 金融应用,计算将来的学费 Exercise05_07
/** * @author 冰樱梦 * 时间:2018年下半年 * 题目:金融应用,计算将来的学费 * */ public class Exercise05_07 { public static vo ...
- Postman Json测试接口
当传递Json数据时: 1.必须添加http头:content-type:application/json,否则会报错(后台取不到相对应的值) 注意:如果服务端只支持UTF-8,但程序未对提交数据进行 ...
- less 命令详解!
less 工具也是对文件或其它输出进行分页显示的工具,应该说是linux正统查看文件内容的工具,功能极其强大.less 的用法比起 more 更加的有弹性.在 more 的时候,我们并没有办法向前面翻 ...
- winform 窗体实现增删改查(CRUD)共用模式
转载:http://www.csframework.com/archive/2/arc-2-20110617-1632.htm 高度封装的编辑窗体 http://www.cnblogs.com/wuh ...
- android 图片上传到服务端 文件损坏问题
在网上找的例子,怎么试都不行. 上传上去之后提示文件损坏,不过最后问题还是找到了. 是因为不能在写入流的byte中写入其他内容 这是网上的例子 如果是要在服务端取文件名,可以在这里写入 在服务端获取文 ...
- javascript模块化有什么意义?
以前,所有的javascript都写在一个文件里,方便只加载一个文件就可以了,但是代码越来越多,必须分成多个文件加载,类似: <script src="1.js">&l ...
- Android修改状态栏颜色全方位教程
关键字:状态栏着色 透明状态栏 沉浸式 白底黑字 Github Demo:https://github.com/imflyn/Eyes 参考文章: Android-transulcent-status ...