LeetCode-551. Student Attendance Record I (Java)
来源:互联网 发布:js中如何定义数组 编辑:程序博客网 时间:2024/05/16 10:36
You are given a string representing an attendance record for a student. The record only contains the following three characters:
- 'A' : Absent.
- 'L' : Late.
- 'P' : Present.
A student could be rewarded if his attendance record doesn't contain more than one 'A' (absent) or more than two continuous 'L' (late).
You need to return whether the student could be rewarded according to his attendance record.
Example 1:
Input: "PPALLP"Output: True
Example 2:
Input: "PPALLL"Output: False------------------------------------------------------------------------------------------------------------------------------------------------------------------------
代码
public class Solution { public boolean checkRecord(String s) { char[] array = s.toCharArray(); int countA = 0; int countL =0; for(int i =0;i<array.length;i++){ if('A' == array[i]){ countA++; if(countA >1){ return false; } } if('L'== array[i]){ countL++; if(countL >2){ return false; } } else{ countL =0; } } return true; }}
阅读全文
0 0
- LeetCode-551. Student Attendance Record I (Java)
- LeetCode 551. Student Attendance Record I
- [LeetCode]551. Student Attendance Record I
- LeetCode 551. Student Attendance Record I
- [leetcode]: 551. Student Attendance Record I
- [leetcode: Python]551. Student Attendance Record I
- [leetcode]551. Student Attendance Record I
- leetcode#551. Student Attendance Record I
- leetcode 551. Student Attendance Record I
- leetcode 551. Student Attendance Record I
- LeetCode-551. Student Attendance Record I
- [LeetCode] 551. Student Attendance Record I
- leetcode 551. Student Attendance Record I
- 551. Student Attendance Record I
- 551. Student Attendance Record I
- 551. Student Attendance Record I
- 551. Student Attendance Record I
- 551. Student Attendance Record I
- 17_cookie(三)
- PAT乙级 1070. 结绳(25)
- 最高的奖励
- 18_cookie(四_补充)
- 19_SevletContext_chat剪辑
- LeetCode-551. Student Attendance Record I (Java)
- 20_chat2
- 多线程
- shell脚本中命令代换:反引号、$()、eval区别
- 21_ServletContext补充
- 如何从源码编译SITL
- C语言获取系统时间方法
- Volatile关键字解读(一)
- 设计模式之适配器模式