Count Number of Ways to Place Houses LeetCode solution in C++

1
class Solution {
2
public:
3
typedef long long ll;
4
ll mod = 1e9 + 7;
5
int countHousePlacements(int n) {
6
ll house = 1, space = 1;
7
ll total = house + space;
8
for (int i = 2; i <= n; i++) {
9
house = space;
10
space = total;
11
total = (house + space) % mod;
12
}
13
return (total * total) % mod;
14
}
15
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0