[LeetCode]552. Student Attendance Record II
来源:互联网 发布:手机单机版进销存软件 编辑:程序博客网 时间:2024/06/06 13:25
https://leetcode.com/problems/student-attendance-record-ii/#/description
A、P、L三种字母,其中A最多出现一次,L最多连续出现两次,问给定长度的字符串最多有多少种可能情况。结果取模1000000007。
dp数组内分为六种情况:
A0L0: A0L1: A0L2: A1L0: A1L1: A1L2:
AxLy表示当前字符串中一共x个A,结尾处一共连续y个Lpublic class Solution { public int checkRecord(int n) { int[] dp = {1, 1, 0, 1, 0, 0}; for (int i = 2; i <= n; i++) { dp = new int[]{sum(dp, 0, 2), dp[0], dp[1], sum(dp, 0, 5), dp[3], dp[4]}; } return sum(dp, 0, 5); } private int sum(int[] dp, int start, int end) { final int MOD = 1000000007; int res = 0; for (int i = start; i <= end; i++) { res = (res + dp[i]) % MOD; } return res; }}
阅读全文
0 0
- 【LeetCode】552. Student Attendance Record II
- [LeetCode]552. Student Attendance Record II
- LeetCode 552. Student Attendance Record II
- leetcode 552. Student Attendance Record II
- leetcode#552. Student Attendance Record II
- [leetcode]552. Student Attendance Record II
- 552. Student Attendance Record II
- 552. Student Attendance Record II
- 552. Student Attendance Record II
- 552. Student Attendance Record II
- 552. Student Attendance Record II
- 552. Student Attendance Record II
- [Leetcode] 552. Student Attendance Record II 解题报告
- [LeetCode] DP之 Student Attendance Record II
- leetcode552. Student Attendance Record II
- LeetCode(六) DP 70.Climbing Stairs&552. Student Attendance Record II
- leetcode 552. Student Attendance Record II & 600. Non-negative Integers without Consecutive Ones
- leetcode 552. Student Attendance Record II 学生出勤记录 + 动态规划DP
- 设计模式六大原则
- Ardupilot -- APM源码笔记二(重制)~ Ardupilot 链接库引导
- 389. Find the Difference
- RecyclerView+CheckBox实现列表数据选择操作
- servlet生命周期
- [LeetCode]552. Student Attendance Record II
- Android 视频录制
- JDBC 远程 SQLSERVER 速度很慢的处理方式
- input输入框禁止显示历史记录
- java实现在线预览----poi操作word转html及03、07版本兼容问题
- You-Get——基于Python3的媒体下载工具
- cent7配置nginx(二),nginx负载均衡的5种策略
- mysql提示Packet for query is too large (1142 > 1024)解决方案
- 均值、方差、协方差、协方差矩阵、特征值、特征向量