Skip to content

Commit 72671da

Browse files
solves student attendancerecord I
1 parent 27c3f04 commit 72671da

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

Diff for: README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@
144144
| 538 | [Convert BST to Greater Tree](https://leetcode.com/problems/convert-bst-to-greater-tree) | Easy | [![Java](assets/java.png)](src/ConvertBSTToGreaterTree.java) [![Python](assets/python.png)](python/convert_bst_to_greater_tree.py) |
145145
| 541 | [Reverse String II](https://leetcode.com/problems/reverse-string-ii) | Easy | [![Java](assets/java.png)](src/ReverseStringII.java/) [![Python](assets/python.png)](python/reverse_string_ii.py) |
146146
| 543 | [Diameter of Binary Tree](https://leetcode.com/problems/diameter-of-binary-tree) | Easy | [![Java](assets/java.png)](src/DiameterOfBinaryTree.java) [![Python](assets/python.png)](python/diameter_of_binary_tree.py) |
147-
| 551 | [Student Attendance Record I](https://leetcode.com/problems/student-attendance-record-i) | Easy | |
147+
| 551 | [Student Attendance Record I](https://leetcode.com/problems/student-attendance-record-i) | Easy | [![Java](assets/java.png)](src/StudentAttendanceRecordI.java) [![Python](assets/python.png)](python/student_attendance_record_I.py) |
148148
| 557 | [Reverse Words in a String III](https://leetcode.com/problems/reverse-words-in-a-string-iii) | Easy | |
149149
| 559 | [Maximum Depth of N-Ary Tree](https://leetcode.com/problems/maximum-depth-of-n-ary-tree) | Easy | |
150150
| 561 | [Array Partition I](https://leetcode.com/problems/array-partition-i) | Easy | |

Diff for: python/student_attendance_record_I.py

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class Solution:
2+
def checkRecord(self, s: str) -> bool:
3+
consecutiveLate, absent = 0, 0
4+
for character in s:
5+
if character == 'L':
6+
consecutiveLate += 1
7+
else:
8+
if character == 'A': absent += 1
9+
consecutiveLate = 0
10+
if consecutiveLate >= 3 or absent >= 2: return False
11+
return True

Diff for: src/StudentAttendanceRecordI.java

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
public class StudentAttendanceRecordI {
2+
public boolean checkRecord(String s) {
3+
int consecutiveLate = 0, absentees = 0;
4+
for (int index = 0 ; index < s.length() ; index++) {
5+
if (s.charAt(index) == 'L') {
6+
consecutiveLate++;
7+
} else {
8+
if (s.charAt(index) == 'A') absentees++;
9+
consecutiveLate = 0;
10+
}
11+
if (absentees >= 2 || consecutiveLate >= 3) {
12+
return false;
13+
}
14+
}
15+
return true;
16+
}
17+
}

0 commit comments

Comments
 (0)