Class Solution
-
- All Implemented Interfaces:
public final class Solution2320 - Count Number of Ways to Place Houses.
Medium
There is a street with
n * 2plots , where there arenplots on each side of the street. The plots on each side are numbered from1ton. On each plot, a house can be placed.Return the number of ways houses can be placed such that no two houses are adjacent to each other on the same side of the street. Since the answer may be very large, return it modulo <code>10<sup>9</sup> + 7</code>.
Note that if a house is placed on the <code>i<sup>th</sup></code> plot on one side of the street, a house can also be placed on the <code>i<sup>th</sup></code> plot on the other side of the street.
Example 1:
Input: n = 1
Output: 4
Explanation:
Possible arrangements:
All plots are empty.
A house is placed on one side of the street.
A house is placed on the other side of the street.
Two houses are placed, one on each side of the street.
Example 2:
Input: n = 2
Output: 9
Explanation: The 9 possible arrangements are shown in the diagram above.
Constraints:
<code>1 <= n <= 10<sup>4</sup></code>
-
-
Constructor Summary
Constructors Constructor Description Solution()
-
Method Summary
Modifier and Type Method Description final IntegercountHousePlacements(Integer n)-
-
Method Detail
-
countHousePlacements
final Integer countHousePlacements(Integer n)
-
-
-
-