문제/릿코드

[릿코드/LeetCode] 551. Student Attendance Record I (파이썬3/Python3)

개 살구 2021. 7. 11. 03:13

문제

https://leetcode.com/problems/student-attendance-record-i/

 

Student Attendance Record I - LeetCode

Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.

leetcode.com


생각

결석은 2번 이상하면 안 되고, 지각는 3일 연속으로 하면 안 되는 듯?

결석은 그냥 += 1하고

지각은 다른 거 나오면 리셋시키고 지각나오면 += 1하면 될 듯?

-


코드

class Solution:
  def checkRecord(self, s: str) -> bool:
    absent = 0
    late = 0
    
    for i in s:
      if i == 'A':
        absent += 1
        late = 0
        if absent == 2:
          break
      elif i == 'L':
        late += 1
        if late == 3:
          break
      else:
        late = 0
          
    if absent >= 2 or late >= 3:
      return False
    else:
      return True