-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathattendance_record1.cpp
More file actions
51 lines (47 loc) · 1.12 KB
/
attendance_record1.cpp
File metadata and controls
51 lines (47 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/*
* =====================================================================================
*
* Filename: attendance_record1.cpp
*
* Description: 551. Student Attendance Record I
*
* Version: 1.0
* Created: 11/11/2025 18:26:28
* Revision: none
* Compiler: gcc
*
* Author: YOUR NAME (),
* Organization:
*
* =====================================================================================
*/
#include <string>
#include <utility>
#include <vector>
#include "gtest/gtest.h"
class Solution {
public:
bool checkRecord(std::string s) {
const int n = s.length();
int count_a = 0;
for (int i = 0; i < n; i++) {
if (s[i] == 'A' && ++count_a >= 2) {
return false;
}
if (i > 1 && s[i] == 'L' && s[i - 1] == 'L' && s[i - 2] == 'L') {
return false;
}
}
return true;
}
};
TEST(Solution, checkRecord) {
std::vector<std::pair<std::string, bool>> cases = {
{"PPALLP", true},
{"PPALLL", false},
{"ALLAPPL", false},
};
for (auto& [s, res] : cases) {
EXPECT_EQ(Solution().checkRecord(s), res);
}
}