Skip to content

Commit

Permalink
Create 1997.First-Day-Where-You-Have-Been-in-All-the-Rooms.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
wisdompeak authored Sep 6, 2021
1 parent 991708c commit 557a21d
Showing 1 changed file with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
class Solution {
long dp[100000];
long M = 1e9+7;
int n;
public:
int firstDayBeenInAllRooms(vector<int>& nextVisit)
{
n = nextVisit.size();
dp[0] = 0;
dp[1] = 2;
long ret = 2;
for (int i=1; i<n-1; i++)
{
int prev = nextVisit[i];
dp[i+1] = dp[i] + (dp[i]-dp[prev] + M +1) % M + 1;
dp[i+1] %= M;
}
return dp[n-1];
}


};

0 comments on commit 557a21d

Please sign in to comment.