551. Student Attendance Record I
来源:互联网 发布:淘宝卖假货封店 编辑:程序博客网 时间:2024/06/04 19:52
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
一开始我以为这道题很简单,就是判断是否出现多于一个A或者多于两个L,当我提交代码的时候,我发觉原来我做错了,我忽略题目two continuous 'L' (late).中的continuous,才知道事情原来没有那么简单,最后改了一下代码,发觉事情也很简单。
AC:
class Solution {public: bool checkRecord(string s) { int lengths = s.length(); int countA = 0; int countL = 0; for (int i = 0; i < lengths; i++) { if(s[i] == 'A') countA++; if(i>=2){ if(s[i] == 'L'&&s[i-1]=='L'&&s[i-2]=='L') return false; } } if(countA>1) return false; return true; }};
阅读全文
0 0
- 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
- 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
- Student Attendance Record I
- Student Attendance Record I
- Student Attendance Record I
- LeetCode 551. Student Attendance Record I
- [LeetCode]551. Student Attendance Record I
- LeetCode 551. Student Attendance Record I
- 测试人员使用idea+git查看代码逻辑
- RCNN总结
- 国际象棋棋盘
- 棋盘问题
- Hibernate中的一级缓存和二级缓存
- 551. Student Attendance Record I
- linux(ubuntu)挂载远程目录到本地
- leetcode(168)Excel Sheet Column Title 简单题
- 微信小程序开发之formId使用(模板消息)
- 用深度学习协助医生诊断肿瘤
- 代码模版化
- RecyclerView嵌套RecyclerView踩的坑
- poj 3461 Oulipo(KMP)
- 第4章 计算属性