[Leetcode] 551. Student Attendance Record I 解题报告
来源:互联网 发布:arm linux gcc gnueabi 编辑:程序博客网 时间:2024/06/05 14:13
题目:
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
思路:
练手题目。咋感觉这道题目在原来出现过?
代码:
class Solution {public: bool checkRecord(string s) { int max_absent = 0, max_late = 0, index = 0; while (index < s.length()) { if (s[index] == 'L') { int late = 1; while (++index < s.length() && s[index] == 'L') { ++late; } max_late = max(max_late, late); } else { max_absent += s[index] == 'A' ? 1 : 0; ++index; } } return max_absent <= 1 && max_late <= 2; }};
阅读全文
0 0
- 【LeetCode】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: Python]551. Student Attendance Record I
- [leetcode]551. Student Attendance Record I
- 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] 551. Student Attendance Record I
- leetcode 551. Student Attendance Record I
- [Leetcode] 552. Student Attendance Record II 解题报告
- 551. Student Attendance Record I
- 551. Student Attendance Record I
- Android自定义AutoCompleteTextView实现自动补全Email
- Linux Mysql 安装及远程权限开放
- 面试中单例模式有几种写法
- C语言实验——矩阵下三角元素之和
- linux系统中mysql控制台的一些常用命令
- [Leetcode] 551. Student Attendance Record I 解题报告
- 【scala 函数定义和调用】Scala的函数调用:普通函数、匿名函数、柯里化函数
- 关于解决Linux下载软件时报错"Failed to connect to github.com port 443"的问题
- 装逼必备:大型分布式网站术语分析
- sudo
- 服务器入侵日志分析(一)——mysql日志位置确定
- freemark 同一个模版用if else导出不同的word,word分页
- Layer关于回调函数细节
- newcoder Wannafly挑战赛6 B-比赛(枚举子集)