Skip to content

Commit dd178be

Browse files
committed
Solved leetcode 790
1 parent 89efc76 commit dd178be

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

Diff for: 790/790.py

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class Solution:
2+
def numTilings(self, n: int) -> int:
3+
goal = 2 * n
4+
cache = [0]*(max(goal + 1, 5))
5+
cache[0] = 0
6+
cache[1] = 0
7+
cache[2] = 1
8+
cache[3] = 1
9+
cache[4] = 2
10+
11+
for i in range(5, goal + 1):
12+
if(i % 2 == 0):
13+
cache[i] = (cache[i - 2] + cache[i - 3] + cache[i - 3] + cache[i - 4]) % (10**9 + 7)
14+
else:
15+
cache[i] = (cache[i - 2] + cache[i - 3]) % (10**9 + 7)
16+
17+
return cache[goal]
18+
19+

0 commit comments

Comments
 (0)