551. Student Attendance Record I
来源:互联网 发布:格林数据 编辑:程序博客网 时间:2024/06/05 17:19
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.
这道题就是注意随时监测,如果A超了1,L超了连续的2就马上return,注意L是连续的,读题要注意。
代码如下:
class Solution {public: bool checkRecord(string s) { bool flag=true; int a[2]; for(int i=0;i<2;i++){ a[i]=0; } for(int i=0;i<s.size();i++){ if(s[i]=='A'){ a[1]=0; a[0]++; if(a[0]>1)return false; } else if(s[i]=='L'){ a[1]++; if(a[1]>2)return false; } else{ a[1]=0; } } 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
- windows环境安装zookeeper图文讲解
- 脚本获取自身ip
- [转帖] 一些算法刷题的网站
- keystone创建service entity和API endpoint
- CWE --- NULL Pointer Dereference -- 例子
- 551. Student Attendance Record I
- linux下sftp上传下载命令
- LDR的用法(ARM指令及伪指令)
- 标准投资回收期
- C语言结构体内存分配——字节码对齐
- 磁疗是不是真的?磁场疗法能促使入睡的实验研究
- php基础语法
- PostgreSQL的数据文件构成
- java.net.SocketException: 断开的管道 (Write failed) 错误,数据库隔一段时间就断开的问题