LeetCode 551. Student Attendance Record I (学生出勤纪录 I)
- '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
题目让我们检查String s,不能有超过1个A 或者 不能连着有超过2个L。
检查A 很容易,检查L 的话,要检查连续的,只要在不是L的情况下,把 count_L reset 回到2就可以了。具体请看code。
Java Solution:
Runtime beats 98.72%
完成日期:04/21/2018
关键词:String
关键点:reset count_L if this char is not 'L'
class Solution
{
public boolean checkRecord(String s)
{
char [] arr = s.toCharArray();
int count_A = 1;
int count_L = 2; for(int i=0; i<arr.length; i++)
{
char c = arr[i]; if(c == 'L') // if char is 'L'
{
count_L--;
} // if char is 'A' or 'P'
else
{
if(c == 'A')
count_A--; count_L = 2; // if this char is not L, set count_L to 2
} if(count_A < 0 || count_L < 0)
return false;
} return true;
}
}
参考资料:n/a
LeetCode 题目列表 - LeetCode Questions List
题目来源:https://leetcode.com/
LeetCode 551. Student Attendance Record I (学生出勤纪录 I)的更多相关文章
- 551 Student Attendance Record I 学生出勤纪录 I
给定一个字符串来代表一个学生的出勤纪录,这个纪录仅包含以下三个字符: 'A' : Absent,缺勤 'L' : Late,迟到 'P' : Present,到场如果一个学生的出勤纪 ...
- [LeetCode] 552. Student Attendance Record II 学生出勤记录之二
Given a positive integer n, return the number of all possible attendance records with length n, whic ...
- [LeetCode] Student Attendance Record II 学生出勤记录之二
Given a positive integer n, return the number of all possible attendance records with length n, whic ...
- [LeetCode] 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 ...
- 552 Student Attendance Record II 学生出勤记录 II
给定一个正整数 n,返回长度为 n 的所有可被视为可奖励的出勤记录的数量. 答案可能非常大,你只需返回结果mod 109 + 7的值.学生出勤记录是只包含以下三个字符的字符串: 1.'A' : ...
- Leetcode551.Student Attendance Record I学生出勤记录1
给定一个字符串来代表一个学生的出勤纪录,这个纪录仅包含以下三个字符: 'A' : Absent,缺勤 'L' : Late,迟到 'P' : Present,到场 如果一个学生的出勤纪录中不超过一个' ...
- 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 ...
随机推荐
- 关于联想笔记本不能连接无线网(wifi),注销后重新登录才可以连接
解决联想笔记本wifi问题(果果) 最近很多使用联想的朋友都遇到了这样一个问题,那就是笔记本的wifi突然不能用了,好吧,其实我个人也遇到了这个问题,但是网上貌似对这个问题并没有给出一个可以解决的办法 ...
- facade模式-服务-配置----系统生成与配置
facade模式对外提供一组相关服务: 对内整合子系统: facade模式的创建过程需要依赖外部的配置. 配置完成以后才能使用服务. 推广开来,所有系统都需要生成与配置,然后才能对外提供服务.
- View Programming Guide for iOS
https://developer.apple.com/library/archive/documentation/WindowsViews/Conceptual/ViewPG_iPhoneOS/Wi ...
- 怎么忽略ESLint校验
方法一: 打开eslint的配置文件.eslintrc.js rules: { // allow async-await 'generator-star-spacing': 'off', // all ...
- CAD设置系统变量(com接口VB语言)
主要用到函数说明: MxDrawXCustomFunction::Mx_SetSysVar 设置系统变量.详细说明如下: 参数 说明 CString sVarName 系统变量名 Value 需要设置 ...
- JavaScipt30(第四个案例)(主要知识点:数组原型链上的一些方法)
承接上文,下面是第四个案例 附上项目链接: https://github.com/wesbos/JavaScript30 const inventors = [ { first: 'Albert', ...
- 【原】Mysql存储关联数组
$fruits= array("apple" => "苹果", "banana" => "香蕉"," ...
- docker 1-->docker compose 转载
转自:http://www.ityouknow.com/docker/2018/03/22/docker-compose.html Docker-Compose 是 Docker 的一种编排服务,是一 ...
- (C/C++学习)21.C++中返回引用和返回对象以及传引用和传对象问题
说明:在学习和编写C++代码时,经常会遇到这样的问题:一个带返回值的函数,到底应该返回值呢,还是应该返回引用呢:在传递参数的时候,是应该传递参数的引用呢,还是应该传值呢?请看下面代码: void my ...
- airfoil polar data during post stall stages (high AOA)
airfoil polar data during post stall stages (high AOA) Table of Contents 1. airfoil polar during pos ...