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
  • 相关阅读:
    Java实现调用API识别图像中的文字并对图片重命名
    推荐大家一个人工智能领域安全信息学方向旗舰会议(EI索引),诚邀广大学子投稿!
    python随笔 1
    Neo4j
    Web项目部署到tomcat外部并配置其他端口访问和无项目名
    springboot项目
    解决找不到参数 问题,MyBatisSystemException
    置顶功能 -- 数据表格的某行数据的置顶功能 -- Demo
    Spring-Task定时任务, (springboot项目, 动态设置时间) -- Demo
    BootStrap-table表格 -- Demo
  • 原文地址:https://www.cnblogs.com/immiao0319/p/8649343.html
Copyright © 2011-2022 走看看