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;
} }
}
551.学生出勤记录I的更多相关文章
- Java实现 LeetCode 551 学生出勤记录 I(暴力大法好)
551. 学生出勤记录 I 给定一个字符串来代表一个学生的出勤记录,这个记录仅包含以下三个字符: 'A' : Absent,缺勤 'L' : Late,迟到 'P' : Present,到场 如果一个 ...
- [Swift]LeetCode552. 学生出勤记录 II | Student Attendance Record II
Given a positive integer n, return the number of all possible attendance records with length n, whic ...
- Leetcode 552.学生出勤记录II
学生出勤记录II 给定一个正整数 n,返回长度为 n 的所有可被视为可奖励的出勤记录的数量. 答案可能非常大,你只需返回结果mod 109 + 7的值. 学生出勤记录是只包含以下三个字符的字符串: ' ...
- 552 Student Attendance Record II 学生出勤记录 II
给定一个正整数 n,返回长度为 n 的所有可被视为可奖励的出勤记录的数量. 答案可能非常大,你只需返回结果mod 109 + 7的值.学生出勤记录是只包含以下三个字符的字符串: 1.'A' : ...
- Java实现 LeetCode 552 学生出勤记录 II(数学转换?还是动态规划?)
552. 学生出勤记录 II 给定一个正整数 n,返回长度为 n 的所有可被视为可奖励的出勤记录的数量. 答案可能非常大,你只需返回结果mod 109 + 7的值. 学生出勤记录是只包含以下三个字符的 ...
- 力扣(LeetCode)学生出勤记录I 个人题解
给定一个字符串来代表一个学生的出勤记录,这个记录仅包含以下三个字符: 'A' : Absent,缺勤 'L' : Late,迟到 'P' : Present,到场 如果一个学生的出勤记录中不超过一个' ...
- [LeetCode] Student Attendance Record I 学生出勤记录之一
You are given a string representing an attendance record for a student. The record only contains the ...
- 551. 学生出勤纪录 I
给定一个字符串来代表一个学生的出勤纪录,这个纪录仅包含以下三个字符: 'A' : Absent,缺勤 'L' : Late,迟到 'P' : Present,到场 如果一个学生的出勤纪录中不超过一个' ...
- Leetcode551.Student Attendance Record I学生出勤记录1
给定一个字符串来代表一个学生的出勤纪录,这个纪录仅包含以下三个字符: 'A' : Absent,缺勤 'L' : Late,迟到 'P' : Present,到场 如果一个学生的出勤纪录中不超过一个' ...
随机推荐
- js隐藏元素、jquery隐藏、css隐藏
$("#yh").css("display","none");//隐藏元素 $("#yh").css("dis ...
- CodeForces 959E Mahmoud and Ehab and the xor-MST (MST+找规律)
<题目链接> 题目大意: 给定一个数n,代表有一个0~n-1的完全图,该图中所有边的边权为两端点的异或值,求这个图的MST的值. 解题分析: 数据较大,$10^{12}$个点的完全图,然后 ...
- WebLogic使用总结(一)——WebLogic安装
一.下载WebLogic 到Oracle官网http://www.oracle.com/ 下载WebLogic(根据自己的情况选择),本文档下载的是Generic WebLogic Server an ...
- 关于H5页面在iPhoneX适配
1. iPhoneX的介绍 屏幕尺寸 我们熟知的iPhone系列开发尺寸概要如下: △ iPhone各机型的开发尺寸 转化成我们熟知的像素尺寸: △ 每个机型的多维度尺寸 倍图其实就是像素尺寸和开 ...
- Selenium + Python +CSV
绪论 首先写这个文章的时候仅仅花了2个晚上(我是菜鸟所以很慢),自己之前略懂selenium,但是不是很懂csv,这次相当于练手了. 第一章 环境介绍 具体实验环境 系统 Windows10教育版 1 ...
- 解决sql_mode=only_full_group_by的问题
1.mysql查询报错: ORDER BY clause is not in GROUP BY..this is incompatible with sql_mode=only_full_group_ ...
- clipboard.js一个可以在移动端一键复制的插件
网址:https://clipboardjs.com/ 使用方法: 1.引入js <script src="dist/clipboard.min.js"></sc ...
- ko学习二,绑定语法
补充上个监控数组ko.observableArray() ko常用的绑定:text绑定,样式绑定,数据数组绑定. visible 绑定.属性绑定 1.visible绑定 <div data-bi ...
- 常用 jq 正则 包含手机正则,邮箱正则。。。
常用 jq 正则规则 1.手机 /^1(3|4|5|7|8)\d{9}$/ 2.qq /^[1-9][0-9]{5,10}$/ 3.邮箱 /^\w+((-\w+)|(\.\w+))*\@[ ...
- linux学习:find用法整理
find path -option [ -print ] [ -exec -ok command ] {} \; path: find命令所查找的目录路径.例如用.来表示当前目录,用/来表示系统根目录 ...