LeetCode – 551. Student Attendance Record I

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  
The only thing to note is that he has three consecutive L's.

public class Solution { public boolean checkRecord(String s) { int a = 0; for(int i=0;i1){ return false; } } if(s.charAt(i) == 'L' && i+2 

This siteOriginal articleAll follow "Attribution-NonCommercial-ShareAlike 4.0 License (CC BY-NC-SA 4.0)Please retain the following annotations when sharing or adapting:

Original author:Jake Tao,source:「LeetCode – 551. Student Attendance Record I」

143
0 0 143

Further Reading

Post a reply

Log inYou can only comment after that.
Share this page
Back to top