【String-easy】551. Student Attendance Record I 学生迟到和旷课
1. 题目原址
https://leetcode.com/problems/student-attendance-record-i/
2. 题目描述
3. 题目大意
给定一个字符串,包含三类字母:A、L、P,如果超过2个A或者连续有三个以上的L出现,那么就返回false,否则返回true
4. 解题思路
使用两个变量来记录L和A字符出现的次数,如果超过给定的次数就返回false。
5. AC代码
class Solution {public boolean checkRecord(String s) {int length = s.length();int l = 0, a = 0;for(int i = 0; i < length; i++) {if(s.charAt(i) == 'L') { // 需要连续三个L,才能返回falsel++;if (l == 3)return false;}else{ // 如果是不连续的,则将L的频率计数置为0l = 0;}if(s.charAt(i) == 'A') { // 如果有两个A存在,才能返回falsea ++;if(a == 2)return false;}}return true; }
}
6. 相似题目
【1】 552. Student Attendance Record II 题目原址:https://leetcode.com/problems/student-attendance-record-ii/
【String-easy】551. Student Attendance Record I 学生迟到和旷课相关推荐
- 551. Student Attendance Record I -- Python
551. Student Attendance Record I You are given a string representing an attendance record for a stud ...
- 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
题目: You are given a string representing an attendance record for a student. The record only contains ...
- LeetCode——552. 学生出勤记录 II(Student Attendance Record II)[困难]——分析及代码(Java)
LeetCode--552. 学生出勤记录 II[Student Attendance Record II][困难]--分析及代码[Java] 一.题目 二.分析及代码 1. 动态规划 (1)思路 ( ...
- 552. Student Attendance Record II(学生出勤记录 II)
552. Student Attendance Record II 博主看到这题时候第一感觉就是DP方法,但是想了一会方程式写不出来,然后开始怀疑是不是动态方程,想了一下过程感觉极其复杂.看了讨论区, ...
- [Swift]LeetCode551. 学生出勤纪录 I | Student Attendance Record I
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★ ➤微信公众号:山青咏芝(shanqingyongzhi) ➤博客园地址:山青咏芝(https://www.cnblog ...
- 【LeetCode】Student Attendance Record I记录学生出勤率
问题描述 You are given a string representing an attendance record for a student. The record only contain ...
- C#LeetCode刷题之#551-学生出勤纪录 I(Student Attendance Record I)
问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/3953 访问. 给定一个字符串来代表一个学生的出勤纪录,这个纪录仅 ...
- leetCode题解 Student Attendance Record I
1.题目描述 You are given a string representing an attendance record for a student. The record only conta ...
- leetcode之Student Attendance Record I(551)
题目: 给定一个字符串来代表一个学生的出勤纪录,这个纪录仅包含以下三个字符: 'A' : Absent,缺勤 'L' : Late,迟到 'P' : Present,到场 如果一个学生的出勤纪录中不超 ...
最新文章
- Android Json解析方法
- java代码二进制转为十六进制_Java 中二进制转换成十六进制的两种实现方法
- 009_BeanUtils的使用
- GitHub的10,000个最受欢迎的Java项目-以下是它们使用的顶级库
- 高精度人脸表情识别(附GitHub地址)
- 2017.5.8 文化之旅 思考记录
- 使用jQuery获取表格内容、:nth-child() 选择器用法
- 人体塑造教程+源文件+录象教程
- 学习网络编程第一步,安装NetAssist网络调试助手
- cs231n图像分类笔记(上)学习记录
- java+webrtc+回声消除,WebRTC回声消除(2)
- 手把手教你申请计算机软件著作权(4)——资料邮寄
- 微软亚洲研究院院长换帅!复旦校友周礼栋博士升任新院长
- 斐波那契数列(入门c语言)
- 问题 F: 解救小哈
- 关于element upload上传时额外参数的问题
- 易优EyouCMS手机端url路径改为/mobile/方案(非自带m.xxx.com二级域名方案)
- [Practical.Vim(2012.9)].Drew.Neil.Tip10学习摘要
- 安搭Share爱情人生
- ProtoBuf 生成 Go 代码去掉 JSON tag omitempty