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
class Solution(object):
def checkRecord(self, s):
"""
:type s: str
:rtype: bool
"""
num_A=0
num_L=0 for i in s:
if i=='L':
if num_L>1:
return False
else:
num_L+=1
elif i=='A':
if num_A>0:
return False
else:
num_A+=1
num_L=0
else:
num_L=0
if num_A>1:
return False
return True

  

[LeetCode&Python] Problem 551. Student Attendance Record I的更多相关文章

  1. 【leetcode_easy】551. Student Attendance Record I

    problem 551. Student Attendance Record I 题意: solution: class Solution { public: bool checkRecord(str ...

  2. 551. Student Attendance Record I【easy】

    551. Student Attendance Record I[easy] You are given a string representing an attendance record for ...

  3. 551. Student Attendance Record I 从字符串判断学生考勤

    [抄题]: You are given a string representing an attendance record for a student. The record only contai ...

  4. 【LeetCode】551. Student Attendance Record I 解题报告(Java & Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 正则表达式 统计 日期 题目地址:https://l ...

  5. LeetCode 551. Student Attendance Record I (学生出勤纪录 I)

    You are given a string representing an attendance record for a student. The record only contains the ...

  6. LeetCode 551. Student Attendance Record I (C++)

    题目: You are given a string representing an attendance record for a student. The record only contains ...

  7. 551. Student Attendance Record I + Student Attendance Record II

    ▶ 一个学生的考勤状况是一个字符串,其中各字符的含义是:A 缺勤,L 迟到,P 正常.如果一个学生考勤状况中 A 不超过一个,且没有连续两个 L(L 可以有多个,但是不能连续),则称该学生达标(原文表 ...

  8. 551 Student Attendance Record I 学生出勤纪录 I

    给定一个字符串来代表一个学生的出勤纪录,这个纪录仅包含以下三个字符:    'A' : Absent,缺勤    'L' : Late,迟到    'P' : Present,到场如果一个学生的出勤纪 ...

  9. 551. Student Attendance Record I

    static int wing=[]() { std::ios::sync_with_stdio(false); cin.tie(NULL); ; }(); class Solution { publ ...

随机推荐

  1. 通过BeanPostProcessor理解Spring中Bean的生命周期

    通过BeanPostProcessor理解Spring中Bean的生命周期及AOP原理 Spring源码解析(十一)Spring扩展接口InstantiationAwareBeanPostProces ...

  2. nodejs 解析excel文件

    app.js: var FileUpload = require('express-fileupload') app.use(FileUpload()); service.js: npm instal ...

  3. C++手机通讯录排序

    参考:https://www.cnblogs.com/lhwblog/p/6486036.html Qt 4.8.4 vs2008 #include <QtGui/QApplication> ...

  4. cin.get()函数使用例子

    #include <iostream>using namespace std; int k = 0; int main(){ char a[1000]; char c; do { cin. ...

  5. python 列表切片

    列表切片是python语言独有的特征,大大方便了我们的编码. 首先,在介绍切片之前,必须要知道一个知识,就是python列表的读写,下标可以使用负数. insert,get,set 操作均可传入负数下 ...

  6. MyEclipse常用设置和快捷键

    Java快捷键 1.注释快捷键 先敲/  再敲两个**     Enter 回车 2.system.out.println(); 常用设置 [子类继承父类] [编码字体设置] 删除当前行:ctrl+d ...

  7. laravel创建新的提交数据

    public function store() { $this->validate(request(),[ 'title'=>'required|string|max:100|min:10 ...

  8. win7 php nginx 启动命令

    1 php 启动命令 @echo off e: cd E:/php-/ echo "php is starting on port 9007, php_version is 7.0.6&qu ...

  9. centos6.5 安装php-5.6.31

    1 从PHP官网下载所需要的PHP版本 下载地址:  http://php.net/get/php-5.6.31.tar.gz/from/a/mirror  把下载好的文件上传到服务器 2 安装PHP ...

  10. http协议与浏览器缓存

    http协议与浏览器缓存 F5刷新与在地址栏回车的区别 链接