zoukankan      html  css  js  c++  java
  • 551. Student Attendance Record I 从字符串判断学生考勤

    [抄题]:

    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;
        }
    }
    View Code
  • 相关阅读:
    一个cs架构的在线考试系统
    TreeComboBox控件范例
    new和override修饰符的区别
    Hello cnblogs
    MapInfo图层坐标系统转换
    C#调用新浪微博API生成RSS资源文件
    MapInfo图层格式转ArcGIS图层格式
    用ArcGIS的ArcToolbox进行地图切割
    VS2008智能提示消失的解决方法
    【学习笔记】零基础C#窗口程序开发入门
  • 原文地址:https://www.cnblogs.com/immiao0319/p/8649343.html
Copyright © 2011-2022 走看看