LeetCode Student Attendance Record I
原题链接在这里:https://leetcode.com/problems/student-attendance-record-i/description/
题目:
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
题解:
计算'A'的个数和连续'L'的长度.
Time Complexity: O(s.length()). Space: O(1).
AC Java:
class Solution {
public boolean checkRecord(String s) {
int countA = 0;
int lengthL = 0;
for(int i = 0; i<s.length(); i++){
char c = s.charAt(i);
if(c == 'A'){
countA++;
lengthL = 0;
}else if(c == 'L'){
lengthL++;
}else{
lengthL = 0;
}
if(countA>1 || lengthL>2){
return false;
}
}
return true;
}
}
LeetCode Student Attendance Record I的更多相关文章
- [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] 552. Student Attendance Record II 学生出勤记录之二
Given a positive integer n, return the number of all possible attendance records with length n, whic ...
- 【leetcode】552. Student Attendance Record II
题目如下: Given a positive integer n, return the number of all possible attendance records with length n ...
- [Swift]LeetCode552. 学生出勤记录 II | Student Attendance Record II
Given a positive integer n, return the number of all possible attendance records with length n, whic ...
- 552. Student Attendance Record II
Given a positive integer n, return the number of all possible attendance records with length n, whic ...
- 551. Student Attendance Record I 从字符串判断学生考勤
[抄题]: You are given a string representing an attendance record for a student. The record only contai ...
- 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 ...
随机推荐
- ES集群性能调优链接汇总
1. 集群稳定性的一些问题(一定量数据后集群变得迟钝) https://elasticsearch.cn/question/84 2. ELK 性能(2) — 如何在大业务量下保持 Elasticse ...
- [原创]spring及springmvc精简版--继承数据源,声明式事物
1.前期:导入c3p0 jar包,相关数据库连接jar包,我用的是mysql 2.关注事物管理器的配置和AOP配置 代码: 核心关注bean配置文件 application.xml <?xml ...
- Java远程执行Shell命令
1. Jar包:ganymed-ssh2-build210.jar 2. 步骤: a) 连接: Connection conn = new Connection(ipAddr); conn.conne ...
- setup in xunit
https://xunit.github.io/docs/shared-context Shared Context between Tests It is common for unit test ...
- Datax官方笔记总结
# DataX DataX 是阿里巴巴集团内被广泛使用的离线数据同步工具/平台,实现包括 MySQL.SQL Server.Oracle.PostgreSQL.HDFS.Hive.HBase.OTS. ...
- hive学习6
将查询结果集写入另一个表中的时候报了这个错,Dynamic partition strict mode requires at least one static partition column. T ...
- hdu 4737 A Bit Fun 尺取法
A Bit Fun Time Limit: 5000/2500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Proble ...
- js的介绍
需要了解的 如果没有宽带产业的发展,即便是发送JSON这种轻量级数据所带来的延时成本也是不可想象的. 如果没有ECMA-262这份标准文档,各大浏览器在客户端的表现完全不一致,我们就没有办法对Web应 ...
- Python创建插入数据库MySQL
首先要在控制台创建好数据库 mysql -u root -p 创建数据库 查看数据库 -------------------更新分割线(上面为新增...太久没用都忘了SQL基本命令了)-------- ...
- struts2常见配置解决错误There is no mapped for namespace[/] and action name
我碰到这个错误的原因是我把配置文件名写成了Struts.xml,改成struts.xml就可以了. 在确定struts.xml本身并没有写错的情况下,那么发生错误有可能是路径,配置文件名. 如果实在找 ...