Saturday, August 7, 2021

LintCode 1178 · Student Attendance Record I.py

# Approach #1 - Simulation, String - T O(n), S O(1)
class Solution:
"""
@param s: a string
@return: whether the student could be rewarded according to his attendance record
"""
def checkRecord(self, s):
# Write your code here
# if As > 1 or consective Ls > 2, false, otherwise true
countA, countL = 0, 0
for ch in s:
if ch == 'A':
countA += 1
if countA > 1:
return False
countL = 0
elif ch == 'L':
countL += 1
if countL > 2:
return False
else:
countL = 0
return True

No comments:

Post a Comment