551. Student Attendance Record I【easy】
551. Student Attendance Record I【easy】
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
解法一:
- class Solution {
- public:
- bool checkRecord(string s) {
- int num_a = ;
- for (int i = ; i < s.length(); ++i) {
- if (s[i] == 'A') {
- if (++num_a > ) {
- return false;
- }
- }
- if (i > && i < s.length() -
- && s[i] == 'L' && s[i - ] == 'L' && s[i + ] == 'L') {
- return false;
- }
- }
- return true;
- }
- };
解法二:
- public boolean checkRecord(String s) {
- int countA=;
- int continuosL = ;
- int charA = 'A';
- int charL ='L';
- for(int i=;i<s.length();i++){
- if(s.charAt(i) == charA){
- countA++;
- continuosL = ;
- }
- else if(s.charAt(i) == charL){
- continuosL++;
- }
- else{
- continuosL = ;
- }
- if(countA > || continuosL > ){
- return false;
- }
- }
- return true;
- }
参考@rakeshuky 的代码。
解法三:
- public boolean checkRecord(String s) {
- int acount=;
- int lcount=;
- for(char c : s.toCharArray()) {
- if(c=='L') {
- lcount++;
- }
- else {
- lcount=;
- if(c=='A') {
- acount++;
- }
- }
- if(acount> || lcount>=) {
- return false;
- }
- }
- return true;
- }
参考@labs 的代码。
551. Student Attendance Record I【easy】的更多相关文章
- 【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 从字符串判断学生考勤
[抄题]: You are given a string representing an attendance record for a student. The record only contai ...
- 【LeetCode】551. Student Attendance Record I 解题报告(Java & Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 正则表达式 统计 日期 题目地址:https://l ...
- 551. Student Attendance Record I + Student Attendance Record II
▶ 一个学生的考勤状况是一个字符串,其中各字符的含义是:A 缺勤,L 迟到,P 正常.如果一个学生考勤状况中 A 不超过一个,且没有连续两个 L(L 可以有多个,但是不能连续),则称该学生达标(原文表 ...
- [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 (C++)
题目: You are given a string representing an attendance record for a student. The record only contains ...
- 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
static int wing=[]() { std::ios::sync_with_stdio(false); cin.tie(NULL); ; }(); class Solution { publ ...
- 551 Student Attendance Record I 学生出勤纪录 I
给定一个字符串来代表一个学生的出勤纪录,这个纪录仅包含以下三个字符: 'A' : Absent,缺勤 'L' : Late,迟到 'P' : Present,到场如果一个学生的出勤纪 ...
随机推荐
- 微服务之SpringCloud实战(四):SpringCloud Eureka源码分析
Eureka源码解析: 搭建Eureka服务的时候,我们会再SpringBoot启动类加上@EnableEurekaServer的注解,这个注解做了一些什么,我们一起来看. 点进@EnableEure ...
- javolution-core-java-6.1.0.jar 的使用
官方网址:http://javolution.org/apidocs/javolution/io/Struct.html 第一步:导包 第二步:创建继承的结构体 结构体定义如下所示: public c ...
- JNI概述
JNI是Java Native Interface的缩写,它提供了若干的API实现了Java和其他语言的通信(主要是C&C++). JNI 让你在利用强大 Java 平台的同时,使你仍然可以用 ...
- Inno Setup入门(一)——最简单的安装脚本
地址:http://379910987.blog.163.com/blog/static/3352379720110238252326/ 一个最简单的安装脚本: 1.最简单的安装文件脚本: [setu ...
- JS面向对象函数的四种调用模式
函数的四种调用模式 概念 在 js 中,无论是函数, 还是方法, 还是事件, 还是构造器,...这些东西的本质都是函数 函数, 方法, 事件, 构造器,...只是所处的位置不同 这四种模式分别是 函数 ...
- 激活office2010出现“Failed to inject memory”错误
使用Office 2010 Toolkit 2.2.3激活office2010的时候,出现Failed to inject memory!错误,原因是前期使用KM激活过office 2010,然后默认 ...
- 【翻译】自定义 UIViewController Transitions
原文地址:http://www.shinobicontrols.com/blog/posts/2013/10/03/ios7-day-by-day-day-10-custom-uiviewcontro ...
- mongodb_命令行
一.打开命令行 cmd --> cd C:\Program Files\MongoDB\Server\3.0\bin\ --> mongo.exe 二.连接远程机器命令行工具 1.连接 ...
- Kubernetes DNS的配置
Kubernetes集群机制通过DNS进行服务名和ip的映射,如果没有配置dns,你可以通过下面命令查询到集群ip kubectl get svc --namespace=kube-system 得到 ...
- 【AS3 Coder】任务九:游戏新手引导的制作原理(下)
在上一篇教程中,我们了解了一套我自创的新手引导管理框架的使用原理,那么在本篇教程中,我们将考虑新手引导制作中可能遇到的一些棘手问题及探讨其解决方案.Are you ready my baby? Let ...