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 ...
随机推荐
- 接口与抽象类的区别-Java
概念-抽象类: 类是对某一个对象的具体描述,抽象类则是对有共通之处的对象,描述共通之处的类;包含抽象方法的类一定的抽象类,抽象类并不一定包含抽象方法;抽象类中可以有数据成员,但数据成员必须是stati ...
- 三维重建:GitHub百度Apollo 2.0
GitHub:https://github.com/ApolloAuto/apollo 1. 关于Apollo的数据:Apollo的数据会如何开放? 自动驾驶数据将包括具有高分辨率图像和像素级别标注的 ...
- java读取03、07版EXCEL
03版excel,需要用到jxl.jar这个jar包 package test.poi; import java.io.File; import java.io.IOException; import ...
- golang zip 压缩,解压(含目录文件)
每天学习一点go src. 今天学习了zip包的简单使用,实现了含目录的压缩与解压. 写了两个方法,实现了压缩.解压. package ziptest import ( "archive/z ...
- URL解析-URLComponents
let components = URLComponents(url: fakeUrl, resolvingAgainstBaseURL: false)! http://10.100.140.84/m ...
- Win7访问不了WINXP共享文件
用win xp的机器可以访问,但用win 7的机器无法访问共享文件 提示:您没有权限访问.请与网络管理员联系请求访问权限 网上找了相应的资料 做了如下动作 1. 打开网上邻居→本地连接→属性里,“看是 ...
- [Linux]正则表达式和grep使用【转载】
[Linux]正则表达式和grep使用 2018年12月05日 23:45:54 祥知道 阅读数 78 标签: 正则表达式grepLinuxegrep 更多 个人分类: Linux 所属专栏: Li ...
- 26-Ubuntu-文件和目录命令-其他命令-管道
管道 Linux允许将一个命令的输出可以通过管道作为另一个命令的输入. 可以理解为现实生活中的管子,管子的一头塞东西进去,另一头取出来,这里的 | 左右分为两端,左端塞东西(写),右端取东西(读). ...
- MongoDB 启动和关闭
重启命令 service mongodb restart 启动命令 mongod -f /data/tools/mongodb/config/config.conf 必须要带配置文件才能启动 关闭命令 ...
- 如何同步iframe与嵌入内容的高度
最近频繁的做一些通过iframe在a页面嵌入b页面需求.总结下来,有以下问题需要解决 1.如何同步iframe与嵌入内容的高度 2.将b页面载入到a页面后,如何隐藏掉b页面上的元素,如左导航,顶部导航 ...