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:
- 'A' : Absent.
- 'L' : Late.
- '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(双引号字符串)方法很方便也很基础,要熟悉 多用
[输入量]:空: 正常情况:特大:特小:程序里处理到的特殊情况:异常情况(不合法不合理的输入):
[画图]:
[一刷]:
- 又错了:布尔型默认情况是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 从字符串判断学生考勤的更多相关文章
- 551. Student Attendance Record I【easy】
551. Student Attendance Record I[easy] You are given a string representing an attendance record for ...
- 【leetcode_easy】551. Student Attendance Record I
problem 551. Student Attendance Record I 题意: solution: class Solution { public: bool checkRecord(str ...
- 551. Student Attendance Record I + Student Attendance Record II
▶ 一个学生的考勤状况是一个字符串,其中各字符的含义是:A 缺勤,L 迟到,P 正常.如果一个学生考勤状况中 A 不超过一个,且没有连续两个 L(L 可以有多个,但是不能连续),则称该学生达标(原文表 ...
- 【LeetCode】551. Student Attendance Record I 解题报告(Java & Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 正则表达式 统计 日期 题目地址:https://l ...
- LeetCode 551. Student Attendance Record I (C++)
题目: You are given a string representing an attendance record for a student. The record only contains ...
- [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 ...
- LeetCode 551. Student Attendance Record I (学生出勤纪录 I)
You are given a string representing an attendance record for a student. The record only contains the ...
- 551 Student Attendance Record I 学生出勤纪录 I
给定一个字符串来代表一个学生的出勤纪录,这个纪录仅包含以下三个字符: 'A' : Absent,缺勤 'L' : Late,迟到 'P' : Present,到场如果一个学生的出勤纪 ...
- 551. Student Attendance Record I
static int wing=[]() { std::ios::sync_with_stdio(false); cin.tie(NULL); ; }(); class Solution { publ ...
随机推荐
- .Net WebApi 添加Swagger
前言 随着互联网技术的发展,现在的网站架构基本都由原来的后端渲染,变成了:前端渲染.先后端分离的形态,而且前端技术和后端技术在各自的道路上越走越远. 前端和后端的唯一联系,变成了API接口:API文档 ...
- Requst Servervariables
Request.ServerVariables("Url") 返回服务器地址 Request.ServerVariables("Path_Info") 客户端提 ...
- cowboy实现websocket
使用cowboy实现websocket主要实现以下回调函数 下面的函数返回值要具体弄清楚原因参考 websocket具体协议 主要就是两个部分 握手和数据传输 -export([init/3]). ...
- 51nod 1995 三子棋
小的时候大家一定玩过“井”字棋吧.也就是在九宫格中,只要任意行.列,或者任意连续对角线上面出现三个相同的,就能获胜.现在小明和小花也在玩三子棋,但是他们不是在九宫格里,而是在3×4的格子里面.现在小明 ...
- Android用Gson解析JSON字符串
在volley框架中有一个 protected Response<Result<T>> parseNetworkResponse(NetworkResponse respons ...
- tornado日志管理
默认数据格式 默认情况下,采用tornado的web框架运行起来之后,任何访问都会直接在控制台输出日志信息,格式如下: [I 160807 09:27:17 web:1971] 200 GET / ( ...
- jquery ajax 跨域设置
xhrFields: { withCredentials: true},crossDomain: true,
- Linux修改数据库的访问权限
以下方法可以帮助你解决这个问题了,下面的语句功能是,建立一个用户为monitor密码admin权限为和root一样.允许任意主机连接.这样你可以方便进行在本地远程操作数据库了. CREATE USER ...
- PHP 16 个编程法则
HP是最好的编程语言.对于PHP开发者来说,掌握一些编程法则是十分重要的.而在PHP中,以双下划线(__)开头的方法称为魔术方法,它们扮演着非常重要的角色. 常用的魔术方法包括: -__constru ...
- composer.phar的作用和安装laravel5.5.4 和 vendor目录
composer.phar有什么作用 是 PHP 用来管理依赖(dependency)关系的工具.你可以在自己的项目中声明所依赖的外部工具库(libraries),Composer 会帮你安装这些依赖 ...