LeetCode 551:Student Attendance Record I (c++)
来源:互联网 发布:网一网络加速器官网 编辑:程序博客网 时间:2024/05/20 05:24
一:题目
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) ormore 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
二:解题思路
学生受到惩罚:
1.大于1个A
2.或者有连续2个以上的L
通过统计A的个数,和查看是否有连续3个L来解决
三:代码实现
class Solution {public: bool checkRecord(string s) { //学生受到惩罚:大于1个A,或者,大于2个连续的L int numA=0; int i; for(i=0;i<s.length();i++){ if(s[i]=='A') numA++; if(numA>1) return false; if(i>=2 && s[i]=='L' && s[i-1]=='L' && s[i-2]=='L') return false; } return true; }};
阅读全文
0 0
- LeetCode 551:Student Attendance Record I (c++)
- leetcode 551 Student Attendance Record I C++
- Leetcode 551 Student Attendance Record I
- LeetCode 551 Student Attendance Record I
- Leetcode 551 Student Attendance Record I
- leetcode 551[easy]-- Student Attendance Record I
- LeetCode 551. Student Attendance Record I (边界处理)
- LeetCode 551. Student Attendance Record I (C++版)
- LeetCode 551. Student Attendance Record I
- 【LeetCode】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
- Linux中yum命令镜像源出错解决方案
- Android开源项目及资源查速表
- 数据结构探险——图篇
- 文章标题
- Android5.x+ 格式化外部存储(u盘, sdcard)的方法
- LeetCode 551:Student Attendance Record I (c++)
- Android-NFC模块学习(1)
- 【面试题】剑指offer13--在O(1)时间删除链表结点
- ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine(); 空指针异常
- Utils--------工具类
- CentOS6.x 安装 Docker 和 Docker Compose
- css如何让文本框中的输入的文字始终垂直居中
- Wix是什么?
- java实现线程间通信的四种方式