【LeetCode】【字符串】题号:*551. 学生出勤记录 I

every blog every motto: You will never know unless you try

0. 前言

生活好难,再坚持坚持!

1. 字符串

在这里插入图片描述

1.1 题目

在这里插入图片描述

1.2

class Solution:
    def checkRecord(self, s: str) -> bool:

        count = {
    
    'A':0,'L':0,'P':0}

        p_flag = 0
        index = 0
        for ele in s:

            count[ele] +=1

            if count['A']>=2:
                return False
            
            if s[index] == 'L' and index < len(s) - 2:
                if s[index+1] == 'L' and s[index+2] == 'L':
                    return False
            
            index += 1

        return True

1.3

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_39190382/article/details/119335969