/*
* @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. 如何避免OOM

    一.减小对象的内存占用 1)使用更加轻量的数据结构 例如,我们可以考虑使用ArrayMap/SparseArray而不是HashMap等传统数据结构. ArrayMap和HashMap主要不同之处在于 ...

  2. [R] R语言for循环机制

    在做数据分段截取的时候,发现for循环的表现和其他语言不太一样. 上代码: :) { i = i + print(i) } 结果: [] [] [] [] 即作为循环计次的i, 并不会因为在循环体中的 ...

  3. Unity项目导入的error

    5.6.3error 如下:An assembly with the same name `UnityEngine.UI' has already been imported. Consider re ...

  4. jdk1.8.0_40 +maven+tomcat7.0+mysql8.0详细安装教程

    (一)  jdk的安装 1.下载jdk推荐下载地址:http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-213 ...

  5. hdfs OutOfMemoryError

    大量推送本地文件到hdfs如下 hadoop fs -put ${local_path} ${hdfs_path}报错. Exception in thread "main" ja ...

  6. 19.3.20 解决pycharm快捷键无法使用问题和熟悉git与码云操作流程

    problem:由于Vim插件导致快捷键无法使用: answer:settings→Plugins→搜索到ideaVim→取消选中→apply→重启pycharm: git:创建仓库→生成公钥(ssh ...

  7. servlet 拦截器 (filter)

    使用: 创建一个类实现javax.servlet.Filter接口,并重写接口中所有的方法: 在web.xml配置所需要拦截的请求. 过程说明: 1>在应用启动的时候就进行装载Filter类(与 ...

  8. Linux 的 date 日期的使用

    解决的问题有: 1:查看当前日期和时间 2:查看前几天的日期,或者后几天的日期. 3:查看上周几的日期,或者下周几的日期. 4:查看前后几小时,分钟.时间 编写一个简单的shell: 输出下个星期二的 ...

  9. 转载--python模块

    模块,用一砣代码实现了某个功能的代码集合. 类似于函数式编程和面向过程编程,函数式编程则完成一个功能,其他代码用来调用即可,提供了代码的重用性和代码间的耦合.而对于一个复杂的功能来,可能需要多个函数才 ...

  10. div盒子水平居垂直中的几种方法

      div盒子水平居垂直中的几种方法<!DOCTYPE html><html>    <head>        <mete charset="ut ...