[LeetCode&Python] Problem 551. Student Attendance Record I
2024-10-18 22:37:54
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(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
最新文章
- placeholder 颜色更改
- Visual Studio 2010中的stdafx.h和targetver.h两个头文件是有什么用?
- Android setTag方法的key问题
- hdu.5212.Code(莫比乌斯反演 &;&; 埃氏筛)
- Oracle数据库3
- Android中MenuInflater实例
- tomcat学习笔记2
- iOS开发—字典转模型,KVC设计模式
- 4、Hbase
- 安装Java
- Oracle事物基础
- Count Color 线段树
- string转QBytearray
- 安装elasticsearch-7.0.0(centos)
- Hive:map字段存储和取用 ( str_to_map函数 )
- gitkraken clone报错 Configured SSH key is invalid
- 安装php rabbitmq扩展,继上一篇安装Rabbitmq
- CSS中一个冒号和两个冒号有什么区别
- python笔记9-字符串操作
- 在global.asax中启动定时任务