File tree 2 files changed +29
-0
lines changed
2 files changed +29
-0
lines changed Original file line number Diff line number Diff line change 339
339
748|[ Shortest Completing Word] ( ./0748-shortest-completing-word.js ) |Easy|
340
340
762|[ Prime Number of Set Bits in Binary Representation] ( ./0762-prime-number-of-set-bits-in-binary-representation.js ) |Easy|
341
341
784|[ Letter Case Permutation] ( ./0784-letter-case-permutation.js ) |Medium|
342
+ 790|[ Domino and Tromino Tiling] ( ./0790-domino-and-tromino-tiling.js ) |Medium|
342
343
791|[ Custom Sort String] ( ./0791-custom-sort-string.js ) |Medium|
343
344
796|[ Rotate String] ( ./0796-rotate-string.js ) |Easy|
344
345
802|[ Find Eventual Safe States] ( ./0802-find-eventual-safe-states.js ) |Medium|
Original file line number Diff line number Diff line change
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
+ } ;
You can’t perform that action at this time.
0 commit comments