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 ...
随机推荐
- LR接口测试---Java Vuser之jdbc查询(调试前)
在eclipse下编写好的代码: import lrapi.lr; import java.sql.Connection; import java.sql.DriverManager; import ...
- re.S解析
转自:https://www.cnblogs.com/xieqiankun/p/re-sinpython.html 在Python的正则表达式中,有一个参数为re.S.它表示“.”(不包含外侧双引号, ...
- React Native组件的结构和生命周期
React Native组件的结构和生命周期 一.组件的结构 1.导入引用 可以理解为C++编程中的头文件. 导入引用包括导入react native定义的组件.API,以及自定义的组件. 1.1 导 ...
- C++(Typedef声明)
typedef 声明: 使用 typedef 为一个已有的类型取一个新的名字.下面是使用 typedef 定义一个新类型的语法: typedef type newname; 例如,下面的语句会告诉编译 ...
- (转)SqlServer2008开启客户端远程连接
原文地址:http://wenku.baidu.com/link?url=MiiJG0SKUUAb3kzrrQtdx0zGIDpsGa7vcGlzqIDe7qcFx5NJ4UlVoPIswxZCHMo ...
- CentOS上oracle 11g R2数据库安装折腾记
1.虚拟机上centos镜像的获取.这里推荐网易镜像站中的CentOS7版本(其他开源镜像站亦可).这里给出链接: http://mirrors.163.com/centos/7.3.1611/iso ...
- 史上最大型广告欺诈活动Methbot:黑客是如何每天赚到500万美元的
根据国外安全专家的最新报告,有一群黑客正在对美国的知名企业和媒体机构进行广告欺诈活动,而这群黑客每天都可以从中赚取三百万到五百万美金. 是的,你没看错,这绝对是人类历史上最牛X的恶意广告欺诈活动!不过 ...
- MFC_2.2 编辑框和文本控件
编辑框和文本控件 1.拖控件 2.绑定变量.用户名密码编辑框控件类型.取名字.用户协议用值类型,默认CString. 设置属性.用户类型.选择mustiline TRUE. AOTO HScroll ...
- Java必知必会的20种常用类库和API
转载:https://blog.csdn.net/u011001084/article/details/79216958 个人感觉工具类对日常开发是很重要的,所以推荐一下这篇文章,虽然有的类库过时了 ...
- 牛客多校Round 5
Solved:3 rank:195 F. take 官方题解:小 A 在打开第 i 个箱子后会交换手中的钻石和第 i 个箱子中的钻石 当且仅当第 i个箱子的钻石是前 i 个箱子打开后出现的所有钻石里最 ...