Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Leetcode_551_Student Attendance Record I #41

Open
lihe opened this issue Dec 11, 2019 · 0 comments
Open

Leetcode_551_Student Attendance Record I #41

lihe opened this issue Dec 11, 2019 · 0 comments
Labels

Comments

@lihe
Copy link
Owner

lihe commented Dec 11, 2019

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
class Solution {
    public boolean checkRecord(String s) {
        int count = 0;
        for(int i = 0; i < s.length() && count < 2; i++){
            if(s.charAt(i) == 'A')
                count++;
        }
        return count < 2 && s.indexOf("LLL") < 0;
    }
}
@lihe lihe added the Leetcode label Dec 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant