[抄题]:

You are given a string representing an attendance record for a student. The record only contains the following three characters:

  1. 'A' : Absent.
  2. 'L' : Late.
  3. '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

[暴力解法]:

时间分析:

空间分析:

[优化后]:

时间分析:

空间分析:

[奇葩输出条件]:

[奇葩corner case]:

[思维问题]:

以为要用for 来循环找L,但是其实还是index更方便

[一句话思路]:

String类的.indexof contains(双引号字符串)方法很方便也很基础,要熟悉 多用

[输入量]:空: 正常情况:特大:特小:程序里处理到的特殊情况:异常情况(不合法不合理的输入):

[画图]:

[一刷]:

  1. 又错了:布尔型默认情况是return true, 一般情况都是正常即正确的

[二刷]:

[三刷]:

[四刷]:

[五刷]:

[五分钟肉眼debug的结果]:

[总结]:

String类的.indexof contains(双引号字符串)方法很方便也很基础

[复杂度]:Time complexity: O(n) Space complexity: O(1)

[英文数据结构或算法,为什么不用别的数据结构或算法]:

[关键模板化代码]:

[其他解法]:

[Follow Up]:

[LC给出的题目变变变]:

552. Student Attendance Record II 具体方案还用DP就不懂了

[代码风格] :

class Solution {public boolean checkRecord(String s) {//ccif (s.length() == 0) {return true;}//judgeif ((s.indexOf("A") != s.lastIndexOf("A")) || (s.contains("LLL"))) return false;//return return true;}
}

View Code

转载于:https://www.cnblogs.com/immiao0319/p/8649343.html

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. LeetCode 551. Student Attendance Record I

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

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

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

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

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

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

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

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

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

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

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

  8. leetCode题解 Student Attendance Record I

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

  9. leetcode之Student Attendance Record I(551)

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

最新文章

  1. java序列化库_java 中序列化(Serializable)
  2. 问题 | FileNotFoundError: [Errno 2] No such file or directory: 'null'
  3. keepalived(8)——http、tcp检测
  4. 设置润乾报表鼠标移到格子上就显示提示内容
  5. javaI/O流小结
  6. 进程同步,异步,互斥
  7. A 附录、ResolvableType
  8. bim建模的过程的几个要点
  9. 电力系统暂态稳定性仿真 matlab/simulink 仿真模型+设计报告
  10. 用C语言编程复数计算器,简单实现C++复数计算器
  11. 亚马逊、速卖通、Shopee阿里国际站、mercari、沃尔玛、newegg、美客多等跨境平台卖家如何有效结合测评,补单打破瓶颈
  12. 列举所有的“四叶玫瑰数”,并统计四叶玫瑰数的个数 四叶玫瑰数:是一个四位数,各个位的数字的四次方的和,为该数字本身
  13. the Contextual Loss论文理解
  14. word段落操作快捷键(一)
  15. 【krpano】可拖拽相框遮罩
  16. 大题历年题合集-信息资源管理
  17. 桂科版计算机工作的奥秘教案,桂科版三年级下册信息技术全册教案.pdf
  18. linux pppoe配置文件,linux pppoe服务器配置
  19. 云服务器被植入挖矿木马,CPU飙升200%
  20. ucosII 消息队列 应用总结

热门文章

  1. java form 上传文件_java通过表单进行文件上传的几种方法
  2. 第一章计算机网络概述答案,第一章 计算机网络概述[3]
  3. php+原生代码+赋值,js重新赋值原生的方法
  4. python 32bit数据结构_python实现bitmap数据结构详解
  5. java mysql 语句解析器_几种基于Java的SQL解析工具的比较与调用
  6. NYOJ 44 子串和
  7. 8086 INC, DEC
  8. kotlin 查找id_Kotlin程序查找Square区域
  9. 操作系统磁盘调度_磁盘调度| 操作系统
  10. 如何在Python中针对一个值检查多个变量?