专栏名称: 每日一道算法题
学习算法是一种信仰,每天都需要坚持!
目录
相关文章推荐
九章算法  ·  提醒一下,想2025靠刷题上岸的码农 ·  昨天  
九章算法  ·  九章算法导师阵容 ·  昨天  
九章算法  ·  寒潮来袭!微软开启“清仓式”裁员! ·  6 天前  
九章算法  ·  被裁6个月,躺平6个月,上岸! ·  5 天前  
51好读  ›  专栏  ›  每日一道算法题

552. Student Attendance Record II

每日一道算法题  · 公众号  · 算法  · 2017-10-28 09:54

正文


Given a positive integer n, return the number of all possible attendance records with length n, which will be regarded as rewardable. The answer may be very large, return it after mod 109 + 7.


A student attendance record is a string that only contains the following three characters:


‘A’ : Absent.

‘L’ : Late.

‘P’ : Present.

A record is regarded as rewardable if it doesn’t contain more than one ‘A’ (absent) or more than two continuous ‘L’ (late).


Example 1:

Input: n = 2

Output: 8 

Explanation:

There are 8 records with length 2 will be regarded as rewardable:

“PP” , “AP”, “PA”, “LP”, “PL”, “AL”, “LA”, “LL”

Only “AA” won’t be regarded as rewardable owing to more than one absent times. 

Note: The value of n won’t exceed 100,000.


提示提交代码后需要用简洁的语言解释一下代码思路~ 谢谢


历史题目和总结见公众号「每日一道算法题」


https://leetcode.com/problems/student-attendance-record-ii/description/







每日一题 小傅讲解 552. Student Attendance Record II: https://youtu.be/06YtJdBG0rk  

https://www.bilibili.com/video/av15711597/