551.学生出勤记录I
链接:551.学生出勤记录I
难度:Easy
标签:字符串
简介:如果学生可以获得出勤奖励,返回 true ;否则,返回 false 。
题解 1 - python
- 编辑时间:2024-08-18
- 执行用时:36ms
- 内存消耗:16.42MB
- 编程语言:python
- 解法介绍:遍历字符串。
class Solution:
    def checkRecord(self, s: str) -> bool:
        return s.count('A') < 2 and 'LLL' not in s
题解 2 - typescript
- 编辑时间:2021-08-17
- 执行用时:72ms
- 内存消耗:39.4MB
- 编程语言:typescript
- 解法介绍:遍历。
function checkRecord(s: string): boolean {
  let ac = 0;
  let lc = 0;
  for (const c of s) {
    if (c === 'A') {
      if (++ac >= 2) return false;
      lc = 0;
    } else if (c === 'L') {
      if (++lc >= 3) return false;
    } else {
      lc = 0;
    }
  }
  return true;
}