This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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