Skip to content

Commit d81301d

Browse files
committed
Add soution 551
1 parent 5c209a9 commit d81301d

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

Diff for: 551_StudentAttendanceRecord1.swift

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
class Solution {
2+
func checkRecord(_ s: String) -> Bool {
3+
var absents = 0
4+
var lates = 0
5+
var lastRecord: Character = "L"
6+
for record in s {
7+
if record == "A" {
8+
absents += 1
9+
if absents > 1 {
10+
return false
11+
}
12+
} else if record == "L" {
13+
if lastRecord == "L" {
14+
lates += 1
15+
} else {
16+
lates = 1
17+
}
18+
19+
if lates > 2 {
20+
return false
21+
}
22+
}
23+
lastRecord = record
24+
}
25+
return true
26+
}
27+
}

0 commit comments

Comments
 (0)