Skip to content

Commit 0796005

Browse files
authored
Create 1997-first-day-where-you-have-been-in-all-the-rooms.js
1 parent 7a7306b commit 0796005

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* @param {number[]} nextVisit
3+
* @return {number}
4+
*/
5+
const firstDayBeenInAllRooms = function(nextVisit) {
6+
const P = 1e9+7;
7+
const n = nextVisit.length;
8+
const f = Array(n).fill(0) ;
9+
f[0] = 0;
10+
11+
for (let i = 1; i < n; i++) {
12+
f[i] = ((
13+
(2 * f[i - 1]) % P
14+
+ P - f[nextVisit[i - 1]]) % P + 2) % P;
15+
}
16+
17+
return f[n - 1];
18+
};

0 commit comments

Comments
 (0)