We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent f3c744b commit 9f9f91bCopy full SHA for 9f9f91b
String/StudentAttendanceRecordI.swift
@@ -0,0 +1,36 @@
1
+/**
2
+ * Question Link: https://leetcode.com/problems/student-attendance-record-i/
3
+ * Primary idea: Iterate the string and check late & absent counts to check the eligibility.
4
+ *
5
+ * Time Complexity: O(n), Space Complexity: O(1)
6
7
+ */
8
+
9
+class StudentAttendanceRecordI {
10
+ func checkRecord(_ s: String) -> Bool {
11
+ var ACount = 0, LCount = 0
12
+ let sChars = Array(s)
13
14
+ for i in 0..<s.count {
15
+ if sChars[i] == "A" {
16
+ ACount += 1
17
18
+ if ACount >= 2 {
19
+ return false
20
+ }
21
+ } else if sChars[i] == "L" {
22
+ if i > 0 && sChars[i - 1] == "L" {
23
+ LCount += 1
24
25
+ if LCount >= 3 {
26
27
28
+ } else {
29
+ LCount = 1
30
31
32
33
34
+ return true
35
36
+}
0 commit comments