551.学生出勤记录I

/*
 * @lc app=leetcode.cn id=551 lang=java
 *
 * [551] 学生出勤记录 I
 *
 * https://leetcode-cn.com/problems/student-attendance-record-i/description/
 *
 * algorithms
 * Easy (46.31%)
 * Total Accepted:    3.5K
 * Total Submissions: 7.6K
 * Testcase Example:  '"PPALLP"'
 *
 * 给定一个字符串来代表一个学生的出勤记录,这个记录仅包含以下三个字符:
 * 
 * 
 * 'A' : Absent,缺勤
 * 'L' : Late,迟到
 * 'P' : Present,到场
 * 
 * 
 * 如果一个学生的出勤记录中不超过一个'A'(缺勤)并且不超过两个连续的'L'(迟到),那么这个学生会被奖赏。
 * 
 * 你需要根据这个学生的出勤记录判断他是否会被奖赏。
 * 
 * 示例 1:
 * 
 * 输入: "PPALLP"
 * 输出: True
 * 
 * 
 * 示例 2:
 * 
 * 输入: "PPALLL"
 * 输出: False
 * 
 * 
 */
class Solution {
    public boolean checkRecord(String s) {
        boolean result = false;
        char[] arr = s.toCharArray();
        if (isOnlyA(arr) && !isTwoL(s)) {
            result = true;
        }

        return result;


        
    }

    //连续的L
    public static boolean isTwoL(String s){
        return s.contains("LLL");
    }

    public static boolean isOnlyA(char[]arr){
        int count = 0;
        for (int i=0;i<arr.length;i++) {
            char temp = arr[i];
            if (temp == 'A') {
                count++;
            }
        }
        if (count>1) {
            return false;
        } else {
            return true;
        }

    }
}

  

posted on 2019-03-01 16:18  airycode  阅读(124)  评论(0编辑  收藏  举报

导航