题目:原题链接(中等)
标签:动态规划
解法 | 时间复杂度 | 空间复杂度 | 执行用时 |
---|
Ans 1 (Python) | O(N)O(N)O(N) | O(1)O(1)O(1) | 40ms (83.33%) |
Ans 2 (Python) | | | |
Ans 3 (Python) | | | |
解法一:
class Solution:_MOD = 10 ** 9 + 7def numTilings(self, n: int) -> int:now = [1, 0, 0, 0] for _ in range(n):nxt = [0, 0, 0, 0]nxt[0] = (now[0] + now[1] + now[2] + now[3]) % self._MODnxt[1] = (now[2] + now[3]) % self._MODnxt[2] = (now[1] + now[3]) % self._MODnxt[3] = (now[0]) % self._MODnow = nxtreturn now[0]