Skip to content

Commit 8ae1b42

Browse files
committed
Student_Attendance_Record_I
1 parent 1b16576 commit 8ae1b42

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

Student_Attendance_Record_I.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# You are given a string representing an attendance record for a student.
2+
# The record only contains the following three characters:
3+
# 'A' : Absent.
4+
# 'L' : Late.
5+
# 'P' : Present.
6+
# A student could be rewarded if his attendance record doesn't contain
7+
# more than one 'A' (absent) or more than two continuous 'L' (late).
8+
#
9+
# You need to return whether the student could be rewarded according to his attendance record.
10+
#
11+
# Example 1:
12+
#
13+
# Input: "PPALLP"
14+
# Output: True
15+
# Example 2:
16+
#
17+
# Input: "PPALLL"
18+
# Output: False
19+
20+
21+
class Solution:
22+
def checkRecord(self, s):
23+
countA = 0
24+
25+
for i in range(len(s)):
26+
if s[i] == 'A':
27+
countA += 1
28+
if (i < len(s) - 2) and s[i] == 'L' and s[i + 1] == 'L' and s[i + 2] == 'L':
29+
return False
30+
31+
if countA > 1:
32+
return False
33+
return True

0 commit comments

Comments
 (0)