This is the 18th day of my participation in the August Genwen Challenge.More challenges in August
Student attendance record I
The original:Leetcode-cn.com/problems/st…
You are given the string S to represent a student's attendance record, each character of which is used to mark the day's attendance (absence, lateness, presence). A student will receive an attendance award if he/she meets both of the following criteria: A student Absent ('A') strictly less than two days in terms of total attendance. Students will not have a record of being late ('L') for 3 consecutive days or more. Return true if the student can earn an attendance award; Otherwise, return false. Example 1: Input: s = "PPALLP" Output: true Explanation: The student has been absent for less than 2 times, and there is no continuous lateness record of 3 days or more. Example 2: Input: s = "PPALLL" Output: false Explanation: The student was late for the last three days in a row and therefore did not qualify for the attendance award. 1 <= s.length <= 1000 s[I] = 'A', 'L' or 'P'Copy the code
Subject analysis
- The significance of ‘P’ is insignificant and can be ignored. The major factors affecting attendance are A and L
- From example 1-2, it can be seen that absence is greater than or equal to 2. Otherwise, those who do not meet the conditions will be rewarded for attendance
Code implementation
class Solution:
def checkRecord(self, s: str) - >bool:
n=s.count("A")
m=s.count("LLL")
if n>=2 or m>=1:
return False
return True
Copy the code
Analysis:
‘is actually based on the example to solve the problem, that is, as long as the number of absences of A is greater than or equal to 2 and the number of consecutive absences of LLL is greater than or equal to 1, it is False;
From the execution result, the efficiency is average, not very ideal; That’s the easiest way to do it, but it still failed twice. `
1. The first failure is an understanding failure.
2, the second failure or cracking is not in place, LLL can occur many times.
conclusion
Whether it's programming, algorithms, or design frameworks, you need to get your head straight and understand your requirements so you can make as few mistakes as possible.