当前位置:网站首页>Leetcode- student attendance record i- simple
Leetcode- student attendance record i- simple
2022-06-13 05:50:00 【AnWenRen】
title :551 Student attendance records I- Simple
subject
Give you a string s Indicates a student's attendance record , Each character is used to mark the attendance of the day ( Absence from duty 、 late 、 Be present ). The record contains only the following three characters :
‘A’:Absent, Absence from duty
‘L’:Late, late
‘P’:Present, Be present
If students can meanwhile The following two conditions are satisfied , You can get attendance reward :Press Total attendance meter , Student absenteeism (‘A’) Strictly Less than two days .
Student Can't There is continuity 3 Heaven or continuity 3 More than days late (‘L’) Record .
If students can get attendance rewards , return true ; otherwise , return false .
Example 1
Input :s = "PPALLP"
Output :true
explain : Students are absent less than 2 Time , And it does not exist. 3 Continuous lateness record of days or more .
Example 2
Input :s = "PPALLL"
Output :false
explain : The students were late for the last three days in a row , Therefore, the conditions for attendance reward are not met .
Tips
1 <= s.length <= 1000
s[i]
by'A'
、'L'
or'P'
Code Java
public boolean checkRecord(String s) {
StringBuilder sb = new StringBuilder(s);
int countA = 0; // Record absence days , if countA >= 2 return false
int countL = 0; // Record late days , if countL == 3 return false
for (int i = 0; i < sb.length(); i++) {
if (sb.charAt(i) == 'A') {
countA ++;
countL = 0;
if (countA >= 2) return false;
} else if (sb.charAt(i) == 'L') {
countL ++;
if (countL == 3) return false;
} else countL = 0;
}
return true;
}
边栏推荐
- 2021.9.30 learning log -postman
- AUTOSAR actual combat tutorial pdf version
- Django uploads local binaries to the database filefield field
- Mongodb multi field aggregation group by
- Tongweb adapts to openrasp
- Bicolor case
- Leetcode- first unique character in string - simple
- Unity游戏优化(第2版)学习记录7
- Working principle of sentinel series (concept)
- 2020 personal annual summary
猜你喜欢
Byte buddy print execution time and method link tracking
OpenGL Mosaic (8)
MongoDB 多字段聚合Group by
powershell优化之一:提示符美化
Mongodb Multi - field Aggregation group by
中断处理过程
The reason why the process cannot be shut down after a spark job is executed and the solution
Function and application scenario of field setaccessible() method
One of PowerShell optimizations: prompt beautification
[China & some provinces and cities] JSON file for offline map visualization
随机推荐
Three paradigms of MySQL
Top slide immersive dialog
OpenGL马赛克(八)
Leetcode- find a difference - simple
Leetcode- find all missing numbers in the array - simple
10 signalstartevent and signalcatchingevent of flowable signal events
Interrupt processing
How MySQL optimizes the use of joint index ABC
JNDI configuration for tongweb7
Missing tag identification in cots RFID systems: bringing the gap between theory and Practice
Etcd understanding of microservice architecture
Leetcode Hamming distance simple
Unity game optimization [Second Edition] learning record 6
Concurrent programming -- source code analysis of thread pool
Working principle of sentinel series (concept)
How to view tongweb logs correctly?
17 servicetask of flowable task
Config server configuration center of Nacos series
Explanation of sentinel series' features, composition and deployment
2 first experience of drools