551. Student Attendance Record I
2017-08-08 14:51
441 查看
551. Student Attendance Record I
Problem Description
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
Implementation
class Solution { public: bool checkRecord(string s) { char rec = 0; int s_len = s.size(); for(int idx = 0; idx < s_len; idx++) { if(s[idx] == 'A') { if(rec & 0xf0) { return false; } else { rec = 0x80; } } else if(s[idx] == 'L') { if(rec & 0x02) { return false; } else { rec++; } } else { rec &= 0xf0; } } return true; } };
相关文章推荐
- 551. Student Attendance Record I
- 【LeetCode】Student Attendance Record I 解题报告
- 551. Student Attendance Record I
- 第十周:( LeetCode552) Student Attendance Record II(c++)
- 551. Student Attendance Record I
- Student Attendance Record I
- Student Attendance Record I
- leetcode551: Student Attendance Record I
- 551. Student Attendance Record I
- 551. Student Attendance Record I
- leetcode 551 Student Attendance Record I C++
- Leetcode 551 Student Attendance Record I
- Student Attendance Record I
- leetcode 551[easy]-- Student Attendance Record I
- leetcode[Student Attendance Record I]//待整理多种解法
- String:551. Student Attendance Record I
- Student Attendance Record I 学生出勤记录之一
- [LeetCode] Student Attendance Record I 学生出勤记录之一
- Leetcode 551 Student Attendance Record I
- 551. Student Attendance Record I