Skip to content

Commit a716608

Browse files
committed
Sync LeetCode submission - Student Attendance Record I (rust)
1 parent 4d3e43b commit a716608

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
impl Solution {
2+
pub fn check_record(s: String) -> bool {
3+
let mut absents = 0;
4+
let mut conseq_late = 0;
5+
let mut late_last = false;
6+
for c in s.chars() {
7+
match c {
8+
'A' => {
9+
if absents == 1 {
10+
return false;
11+
} else {
12+
absents += 1;
13+
late_last = false;
14+
conseq_late = 0;
15+
}
16+
}
17+
'L' => {
18+
// We always add one if there are none
19+
if conseq_late == 0 {
20+
conseq_late += 1;
21+
}
22+
if late_last {
23+
conseq_late += 1;
24+
}
25+
if conseq_late == 3 {
26+
return false;
27+
}
28+
29+
late_last = true;
30+
}
31+
'P' => {
32+
late_last = false;
33+
conseq_late = 0;
34+
}
35+
_ => unreachable!(),
36+
}
37+
}
38+
39+
return true;
40+
}
41+
}

0 commit comments

Comments
 (0)