[抄题]:

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) {
//cc
if (s.length() == 0) {
return true;
} //judge
if ((s.indexOf("A") != s.lastIndexOf("A")) || (s.contains("LLL"))) return false; //return
return true;
}
}

551. Student Attendance Record I 从字符串判断学生考勤的更多相关文章

  1. 551. Student Attendance Record I【easy】

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

  2. 【leetcode_easy】551. Student Attendance Record I

    problem 551. Student Attendance Record I 题意: solution: class Solution { public: bool checkRecord(str ...

  3. 551. Student Attendance Record I + Student Attendance Record II

    ▶ 一个学生的考勤状况是一个字符串,其中各字符的含义是:A 缺勤,L 迟到,P 正常.如果一个学生考勤状况中 A 不超过一个,且没有连续两个 L(L 可以有多个,但是不能连续),则称该学生达标(原文表 ...

  4. 【LeetCode】551. Student Attendance Record I 解题报告(Java & Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 正则表达式 统计 日期 题目地址:https://l ...

  5. LeetCode 551. Student Attendance Record I (C++)

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

  6. [LeetCode&Python] Problem 551. Student Attendance Record I

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

  7. LeetCode 551. Student Attendance Record I (学生出勤纪录 I)

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

  8. 551 Student Attendance Record I 学生出勤纪录 I

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

  9. 551. Student Attendance Record I

    static int wing=[]() { std::ios::sync_with_stdio(false); cin.tie(NULL); ; }(); class Solution { publ ...

随机推荐

  1. 从云主机上下载文件到本地+获取外网地址(linux & Windows)

    云主机上下载有集中方法,腾讯论坛有一遍文章:向云服务器上传下载文件方法汇总 货比三家,最终还是选择了rsync 下载代码如下 rsync ubuntu@123.207.251.217:/var/www ...

  2. Java中小数保留问题

    方式一: 四舍五入   double   f   =   111231.5585;   BigDecimal   b   =   new   BigDecimal(f);   double   f1  ...

  3. Spring和MyBatis整合

    前言:在前面一篇文章中,介绍了单独使用MyBatis连接orace的例子,在这里分享学习下Spring和MyBatis是如何整合的,以具体工程为例子 阅读目录: 1.环境准备 2.搭建工程 2.1.a ...

  4. CLR 对比 JVM

    首先,CLR和JAVA虚拟机(Java Virtual Machine,简称:JVM)并非一个层面的系统.前者可松散地被描述为just-in-time(JIT)优化编译器和垃圾收集器的混合物,而后者仅 ...

  5. (转)Android 使用com.j256.ormlite

    在web开发中经常采用的hibernate,在android也提供了一个ormlite 导入所需jar包后 摘自:http://blog.csdn.net/cuiran/article/details ...

  6. 关于yii2的中文乱码问题

    在数据库配置中这么配就可以了 <?php return [ 'class' => 'yii\db\Connection', 'dsn' => 'mysql:host=127.0.0. ...

  7. Java-Runoob:Java 运算符

    ylbtech-Java-Runoob:Java 运算符 1.返回顶部 1. Java 运算符 计算机的最基本用途之一就是执行数学运算,作为一门计算机语言,Java也提供了一套丰富的运算符来操纵变量. ...

  8. Java-Maven-Runoob:Maven 项目文档

    ylbtech-Java-Maven-Runoob:Maven 项目文档 1.返回顶部 1. Maven 项目文档 本章节我们主要学习如何创建 Maven 项目文档. 比如我们在 C:/MVN 目录下 ...

  9. bootstrap+css进行页面布局

    效果 用到了bootstrap中的表格css.圆形css.以及上一页下一页css. 布局页面,填充数据,实现js动态效果(比如点击下一页,上一页),逐步完善. 不仅仅要会使用bootstrap中的样式 ...

  10. 转载:细说oracle 11g rac 的ip地址

    本文转载自:细说oracle 11g rac 的ip地址 http://blog.sina.com.cn/s/blog_4fe6d4250102v5fa.html 以前搭建oracle rac的时候( ...