Skip to content

Commit 1dd4db2

Browse files
committed
551. 学生出勤记录 I
1 parent 70a83bc commit 1dd4db2

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

Diff for: README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,9 @@
101101
|520|[检测大写字母](https://leetcode.cn/problems/detect-capital/)|[JavaScript](./algorithms/detect-capital.js)|Easy|
102102
|541|[反转字符串 II](https://leetcode.cn/problems/reverse-string-ii/)|[JavaScript](./algorithms/reverse-string-ii.js)|Easy|
103103
|543|[二叉树的直径](https://leetcode.cn/problems/diameter-of-binary-tree/)|[JavaScript](./algorithms/diameter-of-binary-tree.js)|Easy|
104-
|566|[重塑矩阵](https://leetcode.cn/problems/reshape-the-matrix/)|[JavaScript](./algorithms/reshape-the-matrix.js)|Easy|
104+
|551|[学生出勤记录 I](https://leetcode.cn/problems/student-attendance-record-i/)|[JavaScript](./algorithms/student-attendance-record-i.js)|Easy|
105105
|557|[反转字符串中的单词 III](https://leetcode.cn/problems/reverse-words-in-a-string-iii/)|[JavaScript](./algorithms/reverse-words-in-a-string-iii.js)|Easy|
106+
|566|[重塑矩阵](https://leetcode.cn/problems/reshape-the-matrix/)|[JavaScript](./algorithms/reshape-the-matrix.js)|Easy|
106107
|598|[范围求和 II](https://leetcode.cn/problems/range-addition-ii/)|[JavaScript](./algorithms/range-addition-ii.js)|Easy|
107108
|617|[合并二叉树](https://leetcode.cn/problems/merge-two-binary-trees/)|[JavaScript](./algorithms/merge-two-binary-trees.js)|Easy|
108109
|628|[三个数的最大乘积](https://leetcode.cn/problems/maximum-product-of-three-numbers/)|[JavaScript](./algorithms/maximum-product-of-three-numbers.js)|Easy|

Diff for: algorithms/student-attendance-record-i.js

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* @param {string} s
3+
* @return {boolean}
4+
*/
5+
var checkRecord = function (s) {
6+
let absentCount = 0;
7+
let currLateCount = 0;
8+
let maxLateCount = 0;
9+
10+
for (let i = 0; i < s.length; i++) {
11+
if (s[i] === "A") {
12+
absentCount++;
13+
}
14+
if (s[i] === "L") {
15+
currLateCount++;
16+
maxLateCount = Math.max(currLateCount, maxLateCount);
17+
} else {
18+
currLateCount = 0;
19+
}
20+
}
21+
22+
return absentCount < 2 && maxLateCount < 3;
23+
};

0 commit comments

Comments
 (0)