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,到场如果一个学生的出勤纪 ...
随机推荐
- 【单调队列】bzoj1047 [HAOI2007]理想的正方形
先把整个矩阵处理成b[n][m-K+1].c[n][m-K+1]大小的两个矩阵,分别存储每行每K个数中的最大.最小值,然后再通过b.c处理出d.e分别表示K*K大小的子矩阵中的最大.最小值即可.单调队 ...
- C#SerialPort实现串口控制继电器
最近做了一个小系统,麻雀虽小五脏俱全呀,用到各种线程控制,串口控制等技术.其中串口控制最麻烦,因为继电器的响应很快,根据不同的转接口,返回的数据质量是不一样的,所以不能直接wirte,然后马上read ...
- Spring IOC 中三种注入方式
项目错误知识点记录 正文 最近在项目的时候,用到Spring框架,Spring框架提供了一种IOC的自动注入功能,可以很轻松的帮助我们创建一个Bean,这样就省的我们四处写new Object()这样 ...
- mysql用unix时间戳统计一个日期段的数据
select DATE_FORMAT(FROM_UNIXTIME(date),'%Y-%m-%d') as d, count(*) as c from tb where (FROM_UNIXTIME( ...
- WPF 中依赖属性的继承(Inherits)
WPF中依赖属性的值是是可以设置为可继承(Inherits)的,这种模式下,父节点的依赖属性会将其值传递给子节点.例如,数据绑定中经常使用的DataContextProperty: var host ...
- codeforces round #264(div2)
A题 我仅仅想说题意非常坑,一不小心就会wa,哎,不机智的我居然在最后判题的过程中错了,少加一个推断语句. 错的值了,你说呢? #include<map> #include<cm ...
- 【AS3 Coder】任务九:游戏新手引导的制作原理(下)
在上一篇教程中,我们了解了一套我自创的新手引导管理框架的使用原理,那么在本篇教程中,我们将考虑新手引导制作中可能遇到的一些棘手问题及探讨其解决方案.Are you ready my baby? Let ...
- C#写的一个视频转换解码器
C#写的一个视频转换解码器 using System; using System.Collections.Generic; using System.Linq; using System.Text; ...
- APK大小的瘦身的总结:
首先是看了博客:http://blog.csdn.net/sw950729/article/details/64919051 时.认为大神我就是马云飞写的非常有道理.全部自己就自己写了一遍.长话短说: ...
- 常见的七大排序算法Java实现
/** * @author Javen * @Email javenlife@126.com * 2015年12月9日 */ public class Sorting { static int[] a ...