File tree 2 files changed +36
-1
lines changed
2 files changed +36
-1
lines changed Original file line number Diff line number Diff line change 1
- # 1,882 LeetCode solutions in JavaScript
1
+ # 1,883 LeetCode solutions in JavaScript
2
2
3
3
[ https://leetcodejavascript.com ] ( https://leetcodejavascript.com )
4
4
1761
1761
2316|[ Count Unreachable Pairs of Nodes in an Undirected Graph] ( ./solutions/2316-count-unreachable-pairs-of-nodes-in-an-undirected-graph.js ) |Medium|
1762
1762
2317|[ Maximum XOR After Operations] ( ./solutions/2317-maximum-xor-after-operations.js ) |Medium|
1763
1763
2319|[ Check if Matrix Is X-Matrix] ( ./solutions/2319-check-if-matrix-is-x-matrix.js ) |Easy|
1764
+ 2320|[ Count Number of Ways to Place Houses] ( ./solutions/2320-count-number-of-ways-to-place-houses.js ) |Medium|
1764
1765
2336|[ Smallest Number in Infinite Set] ( ./solutions/2336-smallest-number-in-infinite-set.js ) |Medium|
1765
1766
2338|[ Count the Number of Ideal Arrays] ( ./solutions/2338-count-the-number-of-ideal-arrays.js ) |Hard|
1766
1767
2342|[ Max Sum of a Pair With Equal Sum of Digits] ( ./solutions/2342-max-sum-of-a-pair-with-equal-sum-of-digits.js ) |Medium|
Original file line number Diff line number Diff line change
1
+ /**
2
+ * 2320. Count Number of Ways to Place Houses
3
+ * https://leetcode.com/problems/count-number-of-ways-to-place-houses/
4
+ * Difficulty: Medium
5
+ *
6
+ * There is a street with n * 2 plots, where there are n plots on each side of the street. The plots
7
+ * on each side are numbered from 1 to n. On each plot, a house can be placed.
8
+ *
9
+ * Return the number of ways houses can be placed such that no two houses are adjacent to each other
10
+ * on the same side of the street. Since the answer may be very large, return it modulo 109 + 7.
11
+ *
12
+ * Note that if a house is placed on the ith plot on one side of the street, a house can also be
13
+ * placed on the ith plot on the other side of the street.
14
+ */
15
+
16
+ /**
17
+ * @param {number } n
18
+ * @return {number }
19
+ */
20
+ var countHousePlacements = function ( n ) {
21
+ const MOD = 1e9 + 7 ;
22
+ let empty = 1n ;
23
+ let house = 1n ;
24
+
25
+ for ( let i = 2 ; i <= n ; i ++ ) {
26
+ const nextEmpty = ( empty + house ) % BigInt ( MOD ) ;
27
+ const nextHouse = empty ;
28
+ empty = nextEmpty ;
29
+ house = nextHouse ;
30
+ }
31
+
32
+ const sideWays = ( empty + house ) % BigInt ( MOD ) ;
33
+ return Number ( ( sideWays * sideWays ) % BigInt ( MOD ) ) ;
34
+ } ;
You can’t perform that action at this time.
0 commit comments