Skip to content

Latest commit

 

History

History
43 lines (35 loc) · 710 Bytes

551.学生出勤记录-i.md

File metadata and controls

43 lines (35 loc) · 710 Bytes

551.学生出勤记录-i

/*
 * @lc app=leetcode.cn id=551 lang=typescript
 *
 * [551] 学生出勤记录 I
 */

// @lc code=start
function checkRecord(s: string): boolean {}
// @lc code=end

解法 1: 统计数量

function checkRecord(s: string): boolean {
  let l = 0,
    a = 0
  for (const c of s) {
    if (c === 'L') l++
    else l = 0

    if (c === 'A') a++

    if (l === 3) return false
  }
  return a < 2
}

Case

test.each([
  { input: { s: 'PPALLP' }, output: true },
  { input: { s: 'PPALLL' }, output: false },
  { input: { s: 'AAAA' }, output: false },
])('input: s = $input.s', ({ input: { s }, output }) => {
  expect(checkRecord(s)).toEqual(output)
})