/*
* @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;
} }
}

  

551.学生出勤记录I的更多相关文章

  1. Java实现 LeetCode 551 学生出勤记录 I(暴力大法好)

    551. 学生出勤记录 I 给定一个字符串来代表一个学生的出勤记录,这个记录仅包含以下三个字符: 'A' : Absent,缺勤 'L' : Late,迟到 'P' : Present,到场 如果一个 ...

  2. [Swift]LeetCode552. 学生出勤记录 II | Student Attendance Record II

    Given a positive integer n, return the number of all possible attendance records with length n, whic ...

  3. Leetcode 552.学生出勤记录II

    学生出勤记录II 给定一个正整数 n,返回长度为 n 的所有可被视为可奖励的出勤记录的数量. 答案可能非常大,你只需返回结果mod 109 + 7的值. 学生出勤记录是只包含以下三个字符的字符串: ' ...

  4. 552 Student Attendance Record II 学生出勤记录 II

    给定一个正整数 n,返回长度为 n 的所有可被视为可奖励的出勤记录的数量. 答案可能非常大,你只需返回结果mod 109 + 7的值.学生出勤记录是只包含以下三个字符的字符串:    1.'A' : ...

  5. Java实现 LeetCode 552 学生出勤记录 II(数学转换?还是动态规划?)

    552. 学生出勤记录 II 给定一个正整数 n,返回长度为 n 的所有可被视为可奖励的出勤记录的数量. 答案可能非常大,你只需返回结果mod 109 + 7的值. 学生出勤记录是只包含以下三个字符的 ...

  6. 力扣(LeetCode)学生出勤记录I 个人题解

    给定一个字符串来代表一个学生的出勤记录,这个记录仅包含以下三个字符: 'A' : Absent,缺勤 'L' : Late,迟到 'P' : Present,到场 如果一个学生的出勤记录中不超过一个' ...

  7. [LeetCode] Student Attendance Record I 学生出勤记录之一

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

  8. 551. 学生出勤纪录 I

    给定一个字符串来代表一个学生的出勤纪录,这个纪录仅包含以下三个字符: 'A' : Absent,缺勤 'L' : Late,迟到 'P' : Present,到场 如果一个学生的出勤纪录中不超过一个' ...

  9. Leetcode551.Student Attendance Record I学生出勤记录1

    给定一个字符串来代表一个学生的出勤纪录,这个纪录仅包含以下三个字符: 'A' : Absent,缺勤 'L' : Late,迟到 'P' : Present,到场 如果一个学生的出勤纪录中不超过一个' ...

随机推荐

  1. Intervals 差分约束

    题意:给定n个区间[Li,Ri]以及n个整数vi. 现在要有一个集合,使得这个集合和任意[Li,Ri]都有 至少 vi个元素相同. 问这个集合最少要几个元素. 定义S(x) 表示[1,x]中选择的元素 ...

  2. SpringMVC-2-(Controller)

    一)参数类型 @RequestMapping("hello4") @ResponseBody public ModelAndView Hello4( // Servlet的三个参数 ...

  3. 设备唯一标识方法(Unique Identifier):如何在Windows系统上获取设备的唯一标识 zz

    原文地址:http://www.vonwei.com/post/UniqueDeviceIDforWindows.html 唯一的标识一个设备是一个基本功能,可以拥有很多应用场景,比如软件授权(如何保 ...

  4. drf序列化组件

    rest_framework序列化之Serializer 步骤: 1.自定义一个类,继承Serializer类: 2.在类中写要序列化的字段: 3.使用:在views.py文件中,book_ser=B ...

  5. 2019-2-14sql server数据库模糊查询语句

    sql server数据库模糊查询语句   确切匹配: select * from hs_user where ID=123 模糊查询 select * from hs_user where ID l ...

  6. Android应用程序后台加载数据

    从ContentProvider查询你需要显示的数据是比较耗时的.如果你在Activity中直接执行查询的操作,那么有可能导致Activity出现ANR的错误.即使没有发生ANR,用户也容易感知到一个 ...

  7. file_get_contents 在本地测试可以, 但在服务器上报错403

    解决方法: Most likely if you don't get any content while accessing an webpage, probably it doesn't want ...

  8. java学习之路--I/O流

      java基础学习总结——流 一.JAVA流式输入/输出原理

  9. 修改MyEclipse字体大小及颜色

    windows-->prefereces->General-->Appearance-->Colors and Fonts,在右边找到要修改的字体或背景,双击点Edit修改即可 ...

  10. 增值税发票 成都金锐发票IC卡读入

    黑盘-操作  打开发票领购---网络发票分发----点击查询--分发. 白盘操作: