We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 158b16e commit 3132ca4Copy full SHA for 3132ca4
scripts/algorithms/F/First Day Where You Have Been in All the Rooms/First Day Where You Have Been in All the Rooms.cpp
@@ -1,19 +1,20 @@
1
+// Runtime: 301 ms (Top 34.09%) | Memory: 97.1 MB (Top 92.27%)
2
class Solution {
3
public:
4
int firstDayBeenInAllRooms(vector<int>& nextVisit) {
5
int n = nextVisit.size();
6
int mod = 1e9 + 7;
7
long long dp[n];
8
dp[0] = 0;
-
9
+
10
for(int i = 1 ; i < n ; i++)
11
{
12
if(dp[i-1] == nextVisit[i-1])
13
dp[i] = dp[i-1] + 2;
14
else
15
dp[i] = (2 + 2*dp[i-1] + mod - dp[nextVisit[i-1]])%mod;
16
}
17
18
return (int) dp[n-1]%mod;
19
-};
20
+};
0 commit comments