String:551. Student Attendance Record I
来源:互联网 发布:泰安房产每日成交数据 编辑:程序博客网 时间:2024/06/08 03:12
思路很简单,就是统计A和L的个数,A不用说,L的统计是这样的,不仅遇到L要加1,而且遇到不是L的字符要把L置0.这是我写的:
class Solution {public: bool checkRecord(string s) { int countA = 0; int countL = 0; for(int i = 0; i < s.size(); ++i) { if(s[i] == 'A') { countA++; countL = 0; } if(s[i] == 'L') { countL++; if(countL > 2) return false; } if(s[i] == 'P') countL = 0; } if(countA > 1) return false; return true; }};这么简单的东西我写太长了,一个else能解决的事儿我非得用三个if……看别人写的:
class Solution {public: bool checkRecord(string s) { int a=0, l=0; for(int i=0;i<s.size();i++) { if(s[i]=='A') a++; if(s[i]=='L') l++; else l=0; if(a>=2||l>2) return false; } return true; }};
阅读全文
0 0
- String: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
- 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
- Android Studio报错:Failed to resolve:annotationProcessor解决方案
- 怎么把思维导图做的美观、简洁,这次用的不是国外软件
- 对称加密与非对称加密的在数据传输过程中的具体应用
- [HNOI2009]梦幻布丁 启发式链表合并
- IC烘烤条件
- String:551. Student Attendance Record I
- 第32讲项目-输出小星星(全解)
- shc对Shell脚本加密方法及问题处理
- UVA 753 A Plug for UNIX
- Java中Map的遍历
- 菜鸟看RUP,极限编程与敏捷过程
- C#枚举类型-Enum
- 一个很简单的淘宝优惠券搜索助手 大家看看有没有用吧 下载地址:http://pan.baidu.com/s/1skRHTDF
- Android ConstraintLayout图文并茂详解(二)