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,到场如果一个学生的出勤纪 ...
随机推荐
- 1.4(Spring MVC学习笔记)JSON数据交互与RESTful支持
一.JSON数据交互 1.1JSON简介 JSON(JavaScript Object Notation)是一种数据交换格式. 1.2JSON对象结构 {}代表一个对象,{}中写入数据信息,通常为ke ...
- Scala实战高手****第14课:Scala集合上的函数式编程实战及Spark源码鉴赏
package com.dt.spark.scala.bascis object Functional_Itearal { def main(args: Array[String]): Unit ...
- 解决百度 ueditor v1.4.3 编辑器上传图片失真的bug?
项目中,用到百度ueditor编辑器,发现,上传大一点的图片,图片会失真,刚开始还以为是PHP端做了图片压缩,仔细看配置说明,发现是编辑器自带有个自动压缩图片的功能,可恶的是,压缩后的图片失真了! 决 ...
- [Bug]转:使用jquery的 uploadify,在谷歌浏览器上总会崩溃的解决方法
最近做的项目使用了jquery的uploadify,但是在谷歌浏览器测试总是会出现崩溃.如: 因为是java项目. 解决的办法是: 给引入的js加上一个参数,时间戳就可以,防止缓存,使每一次都请求.( ...
- oracle表空间操作语句
1.查看所有表空间及表空间大小: select tablespace_name ,sum(bytes) / 1024 / 1024 as MB from dba_data_files group by ...
- Tomcat部署时war和war exploded的区别
转自徐刘根的Tomcat部署时war和war exploded区别以及平时踩得坑 一.war和war exploded的区别 在使用IDEA开发项目的时候,部署Tomcat的时候通常会出现下边的情况: ...
- ActiveMQ实战-集群
原文:http://blog.csdn.net/lifetragedy/article/details/51869032 ActiveMQ的集群 内嵌代理所引发的问题: 消息过载 管理混乱 如何解决这 ...
- CSS3:绘制图形
CSS画图形,基本上所有的实现都是对边框的角度的调整及组合. 以下不包含兼容浏览器的前缀,请使用时在border-radius前加-moz-.-webkit- .... 1.正常得不得了的矩形 .sq ...
- Linux下使用Python操作MySQL数据库
安装mysql-python 1.下载mysql-python 打开终端: cd /usr/local sudo wget http://nchc.dl.sourceforge.net/sourcef ...
- cpp面向对象编程
如下图,先建好文件, 这里用的是Visual studio 2010 当然也可以用eclipse for cpp,如下图: AbstractShape.h #ifndef ABSTRACTSHAPE_ ...