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,到场 如果一个学生的出勤纪录中不超过一个' ...
随机推荐
- .net core 设置访问静态资源
- Hierarchical clustering:利用层次聚类算法来把100张图片自动分成红绿蓝三种色调—Jaosn niu
#!/usr/bin/python # coding:utf-8 from PIL import Image, ImageDraw from HierarchicalClustering import ...
- (三)ajax请求不同源之cors跨域
一.基本原理 CORS是一个W3C标准,全称是"跨域资源共享"(Cross-origin resource sharing)它允许浏览器向跨源服务器,发出 XMLHttpReque ...
- TypeScript -访问修饰符
class test extends egret.DisplayObjectContainer { public constructor() { /** * 1.不添加构造函数constructor ...
- nginx Provisional headers are shown
项目用的Nginx做的代理,重启电脑后,重启项目和Nginx 浏览器报 Provisional headers are shown 解决: host文件添加: 127.0.0.1 cleaner ...
- lstm bptt推导
深蓝 nlp 180429这个有详细的讲解
- Nestjs Graphql
文档 工作示例 安装依赖: npm i --save @nestjs/graphql apollo-server-express graphql-tools graphql app.module.ts ...
- 【管理篇】用户故事STORY
项目管理中,常常听说story,用户故事 “一开始就做对系统”纯属神话,反之,我们应该去实现今天的用户故事,然后重构,明天再拓展系统.实现新的用户故事.这就是迭代和增量敏捷的精粹所在.
- Math工具类
public static void main(String[] args) { // 工具类,所有方法都以静态方法提供,没有实例存在的意义 // 不提供任何实例的方法,代表当前类属于无状态的. // ...
- 平安银行在开源技术选型上的思考和实践 RocketMQ
小结: 1. https://mp.weixin.qq.com/s/z_c5D8fvHaYvHSczm0nYFA 平安银行在开源技术选型上的思考和实践 平安银行·吴建峰 阿里巴巴中间件 3月7日 随着 ...