관리 메뉴

솜씨좋은장씨

[leetCode] 551. Student Attendance Record I (Python) 본문

Programming/코딩 1일 1문제

[leetCode] 551. Student Attendance Record I (Python)

솜씨좋은장씨 2020. 8. 8. 19:54
728x90
반응형

You are given a string representing an attendance record for a student. The record only contains the following three characters:

  1. 'A' : Absent.
  2. 'L' : Late.
  3. 'P' : Present.

A student could be rewarded if his attendance record doesn't contain more than one 'A' (absent) or more than two continuous 'L' (late).

You need to return whether the student could be rewarded according to his attendance record.

 

Example 1:

Input: "PPALLP"
Output: True

Example 2:

Input: "PPALLL"
Output: False

 

Solution

from collections import Counter
class Solution:
    def checkRecord(self, s: str) -> bool:
        answer = True
        a_count = 0
        
        for i in range(len(s)):
            if s[i] == 'A':
                a_count = a_count + 1
                if a_count == 2:
                    answer = False
                    break
            elif s[i] == 'L' and i+2 < len(s):
                if s[i+1] == 'L' and s[i+2] == 'L':
                    answer = False
                    break
                    
        return answer

 

 

SOMJANG/CODINGTEST_PRACTICE

1일 1문제 since 2020.02.07. Contribute to SOMJANG/CODINGTEST_PRACTICE development by creating an account on GitHub.

github.com

Comments