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) {//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

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/389975.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

使用deploy命令上传jar到私有仓库

打开cmd命令提示符,mvn install是将jar包安装到本地库,mvn deploy是将jar包上传到远程server,install和deploy都会先自行bulid编译检查,如果确认jar包没有问题,可以使用-Dmaven.test.skiptrue参数跳过编译和测试。 全命…

282. 给表达式添加运算符

282. 给表达式添加运算符 给定一个仅包含数字 0-9 的字符串 num 和一个目标值整数 target ,在 num 的数字之间添加 二元 运算符(不是一元)、- 或 * ,返回所有能够得到目标值的表达式。 示例 1:输入: num "123", targ…

java 在底图上绘制线条_使用底图和geonamescache绘制k表示聚类

java 在底图上绘制线条This is the third of four stories that aim to address the issue of identifying disease outbreaks by extracting news headlines from popular news sources.这是四个故事中的第三个,旨在通过从流行新闻来源中提取新闻头条来解决识别疾病…

python selenium处理JS只读(12306)

12306为例 js "document.getElementById(train_date).removeAttribute(readonly);" driver.execute_script(js)time2获取当前时间tomorrow_time 获取明天时间 from selenium import webdriver import time import datetime time1datetime.datetime.now().strftime(&…

Mac上使用Jenv管理多个JDK版本

使用Java时会接触到不同的版本。大多数时候我在使用Java 8,但是因为某些框架或是工具的要求,这时不得不让Java 7上前线。一般情况下是配置JAVA_HOME,指定不同的Java版本,但是这需要人为手动的输入。如果又要选择其他版本&#xff…

交互式和非交互式_发布交互式剧情

交互式和非交互式Python中的Visual EDA (Visual EDA in Python) I like to learn about different tools and technologies that are available to accomplish a task. When I decided to explore data regarding COVID-19 (Coronavirus), I knew that I would want the abilit…

5886. 如果相邻两个颜色均相同则删除当前颜色

5886. 如果相邻两个颜色均相同则删除当前颜色 总共有 n 个颜色片段排成一列,每个颜色片段要么是 ‘A’ 要么是 ‘B’ 。给你一个长度为 n 的字符串 colors ,其中 colors[i] 表示第 i 个颜色片段的颜色。 Alice 和 Bob 在玩一个游戏,他们 轮…

Sunisoft.IrisSkin.SkinEngine 设置winform皮肤

Sunisoft.IrisSkin.SkinEngine se; se new Sunisoft.IrisSkin.SkinEngine { SkinAllForm true, SkinFile "..\..\skin\EmeraldColor2.ssk" };Sunisoft.IrisSkin.SkinEngine skin new Sunisoft.IrisSkin.SkinEngine(); //具体样式文件 地址,可以自行修…

docker 相关操作

docker-compose down //关闭所有容器 docker-compose up //开启所有容器docker-compose restart //重启所有容器单独更新某个容器时用脚本$ docker ps // 查看所有正在运行容器 $ docker stop containerId // containerId 是容器的ID$ docker ps -a // 查看所有容器 $…

电子表格转换成数据库_创建数据库,将电子表格转换为关系数据库,第1部分...

电子表格转换成数据库Part 1: Creating an Entity Relational Diagram (ERD)第1部分:创建实体关系图(ERD) A Relational Database Management System (RDMS) is a program that allows us to create, update, and manage a relational database. Structured Query …

【Vue.js学习】生命周期及数据绑定

一、生命后期 官网的图片说明: Vue的生命周期总结 var app new Vue({el:"#app", beforeCreate: function(){console.log(1-beforeCreate 初始化之前);//加载loading},created: function(){console.log(2-created 创建完成);//关闭loading},be…

5885. 使每位学生都有座位的最少移动次数

5885. 使每位学生都有座位的最少移动次数 一个房间里有 n 个座位和 n 名学生,房间用一个数轴表示。给你一个长度为 n 的数组 seats ,其中 seats[i] 是第 i 个座位的位置。同时给你一个长度为 n 的数组 students ,其中 students[j] 是第 j 位…

Springboot(2.0.0.RELEASE)+spark(2.1.0)框架整合到jar包成功发布(原创)!!!

一、前言 首先说明一下,这个框架的整合可能对大神来说十分容易,但是对我来说十分不易,踩了不少坑。虽然整合的时间不长,但是值得来纪念下!!!我个人开发工具比较喜欢IDEA,创建的sprin…

求一个张量的梯度_张量流中离散策略梯度的最小工作示例2 0

求一个张量的梯度Training discrete actor networks with TensorFlow 2.0 is easy once you know how to do it, but also rather different from implementations in TensorFlow 1.0. As the 2.0 version was only released in September 2019, most examples that circulate …

docker环境 快速使用elasticsearch-head插件

docker环境 快速使用elasticsearch-head插件 #elasticsearch配置 #进入elk容器 docker exec -it elk /bin/bash #head插件访问配置 echo #head插件访问# http.cors.enabled: true http.cors.allow-origin: "*" >>/etc/elasticsearch/elasticsearch.yml#重启el…

476. 数字的补数

476. 数字的补数 给你一个 正 整数 num ,输出它的补数。补数是对该数的二进制表示取反。 例 1:输入:num 5 输出:2 解释:5 的二进制表示为 101(没有前导零位),其补数为 010。所以你…

zabbix网络发现主机

1 功能介绍 默认情况下,当我在主机上安装agent,然后要在server上手动添加主机并连接到模板,加入一个主机组。 如果有很多主机,并且经常变动,手动操作就很麻烦。 网络发现就是主机上安装了agent,然后server自…

python股市_如何使用python和破折号创建仪表板来主导股市

python股市始终关注大局 (Keep Your Eyes on the Big Picture) I’ve been fascinated with the stock market since I was a little kid. There is certainly no shortage of data to analyze, and if you find an edge you can make some easy money. To stay on top of the …

阿里巴巴开源 Sentinel,进一步完善 Dubbo 生态

为什么80%的码农都做不了架构师?>>> 阿里巴巴开源 Sentinel,进一步完善 Dubbo 生态 Sentinel 开源地址:https://github.com/alibaba/Sentinel 转载于:https://my.oschina.net/dyyweb/blog/1925839

数据结构与算法 —— 链表linked list(01)

链表(维基百科) 链表(Linked list)是一种常见的基础数据结构,是一种线性表,但是并不会按线性的顺序存储数据,而是在每一个节点里存到下一个节点的指针(Pointer)。由于不必须按顺序存储,链表在插入的时候可以…