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 学生迟到和旷课相关推荐

  1. 551. Student Attendance Record I -- Python

    551. Student Attendance Record I You are given a string representing an attendance record for a stud ...

  2. 551. Student Attendance Record I 从字符串判断学生考勤

    [抄题]: You are given a string representing an attendance record for a student. The record only contai ...

  3. LeetCode 551. Student Attendance Record I

    题目: You are given a string representing an attendance record for a student. The record only contains ...

  4. LeetCode——552. 学生出勤记录 II(Student Attendance Record II)[困难]——分析及代码(Java)

    LeetCode--552. 学生出勤记录 II[Student Attendance Record II][困难]--分析及代码[Java] 一.题目 二.分析及代码 1. 动态规划 (1)思路 ( ...

  5. 552. Student Attendance Record II(学生出勤记录 II)

    552. Student Attendance Record II 博主看到这题时候第一感觉就是DP方法,但是想了一会方程式写不出来,然后开始怀疑是不是动态方程,想了一下过程感觉极其复杂.看了讨论区, ...

  6. [Swift]LeetCode551. 学生出勤纪录 I | Student Attendance Record I

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★ ➤微信公众号:山青咏芝(shanqingyongzhi) ➤博客园地址:山青咏芝(https://www.cnblog ...

  7. 【LeetCode】Student Attendance Record I记录学生出勤率

    问题描述 You are given a string representing an attendance record for a student. The record only contain ...

  8. C#LeetCode刷题之#551-学生出勤纪录 I​​​​​​​(Student Attendance Record I)

    问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/3953 访问. 给定一个字符串来代表一个学生的出勤纪录,这个纪录仅 ...

  9. leetCode题解 Student Attendance Record I

    1.题目描述 You are given a string representing an attendance record for a student. The record only conta ...

  10. leetcode之Student Attendance Record I(551)

    题目: 给定一个字符串来代表一个学生的出勤纪录,这个纪录仅包含以下三个字符: 'A' : Absent,缺勤 'L' : Late,迟到 'P' : Present,到场 如果一个学生的出勤纪录中不超 ...

最新文章

  1. Android Json解析方法
  2. java代码二进制转为十六进制_Java 中二进制转换成十六进制的两种实现方法
  3. 009_BeanUtils的使用
  4. GitHub的10,000个最受欢迎的Java项目-以下是它们使用的顶级库
  5. 高精度人脸表情识别(附GitHub地址)
  6. 2017.5.8 文化之旅 思考记录
  7. 使用jQuery获取表格内容、:nth-child() 选择器用法
  8. 人体塑造教程+源文件+录象教程
  9. 学习网络编程第一步,安装NetAssist网络调试助手
  10. cs231n图像分类笔记(上)学习记录
  11. java+webrtc+回声消除,WebRTC回声消除(2)
  12. 手把手教你申请计算机软件著作权(4)——资料邮寄
  13. 微软亚洲研究院院长换帅!复旦校友周礼栋博士升任新院长
  14. 斐波那契数列(入门c语言)
  15. 问题 F: 解救小哈
  16. 关于element upload上传时额外参数的问题
  17. 易优EyouCMS手机端url路径改为/mobile/方案(非自带m.xxx.com二级域名方案)
  18. [Practical.Vim(2012.9)].Drew.Neil.Tip10学习摘要
  19. 安搭Share爱情人生
  20. ProtoBuf 生成 Go 代码去掉 JSON tag omitempty

热门文章

  1. CPC认证的常规测试项目
  2. g的python实现_Python gevent协程切换实现详解
  3. win10安装SVN失败问题汇总
  4. 安卓ps2模拟器_安卓PSP模拟器评测:火影忍者究极冲击
  5. css相对图片加文字,html+css怎么在图片上添加文字
  6. 各种快捷键组合操作让Spotlight搜索变得无比强大
  7. 边境的悍匪—机器学习实战:第十一章 训练深度神经网络
  8. ESP8266连接TFT(ST7789)配置说明
  9. 利用多线程中线程休眠----sleep实现简单的计时器以及时钟功能
  10. 从零开始学Python【23】--线性回归诊断(第二部分)