Skip to content

Commit 7212530

Browse files
committed
Add solution #790
1 parent 01cc2d5 commit 7212530

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,7 @@
339339
748|[Shortest Completing Word](./0748-shortest-completing-word.js)|Easy|
340340
762|[Prime Number of Set Bits in Binary Representation](./0762-prime-number-of-set-bits-in-binary-representation.js)|Easy|
341341
784|[Letter Case Permutation](./0784-letter-case-permutation.js)|Medium|
342+
790|[Domino and Tromino Tiling](./0790-domino-and-tromino-tiling.js)|Medium|
342343
791|[Custom Sort String](./0791-custom-sort-string.js)|Medium|
343344
796|[Rotate String](./0796-rotate-string.js)|Easy|
344345
802|[Find Eventual Safe States](./0802-find-eventual-safe-states.js)|Medium|
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* 790. Domino and Tromino Tiling
3+
* https://leetcode.com/problems/domino-and-tromino-tiling/
4+
* Difficulty: Medium
5+
*
6+
* You have two types of tiles: a 2 x 1 domino shape and a tromino shape. You may rotate
7+
* these shapes.
8+
*
9+
* Given an integer n, return the number of ways to tile an 2 x n board. Since the answer
10+
* may be very large, return it modulo 109 + 7.
11+
*
12+
* In a tiling, every square must be covered by a tile. Two tilings are different if and
13+
* only if there are two 4-directionally adjacent cells on the board such that exactly
14+
* one of the tilings has both squares occupied by a tile.
15+
*/
16+
17+
/**
18+
* @param {number} n
19+
* @return {number}
20+
*/
21+
var numTilings = function(n) {
22+
const MOD_VALUE = Math.pow(10, 9) + 7;
23+
const dp = { 1: 1, 2: 2, 3: 5 };
24+
for (let i = 4; i <= n; i++) {
25+
dp[i] = (2 * dp[i - 1] + dp[i - 3]) % MOD_VALUE;
26+
}
27+
return dp[n];
28+
};

0 commit comments

Comments
 (0)