Skip to content

Commit c6a419f

Browse files
author
Ihssaneabousshal
committed
Runtime: 149 ms (Top 22.45%) | Memory: 56.7 MB (Top 20.41%)
1 parent 0caf030 commit c6a419f

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Runtime: 149 ms (Top 22.45%) | Memory: 56.7 MB (Top 20.41%)
12
class Solution {
23
long[][][] dp;
34
int mod = 1_000_000_007;
@@ -6,31 +7,31 @@ public int dieSimulator(int n, int[] rollMax) {
67
for(long[][] row: dp)
78
for(long[] col: row)
89
Arrays.fill(col, -1);
9-
10+
1011
return (int)helper(n, 0, 0, rollMax, 0);
1112
}
12-
13+
1314
private long helper(int n, int dice, int prev, int[] rollMax, int runs)
1415
{
1516
if(n == dice)
1617
return 1;
17-
18+
1819
if(dp[dice][prev][runs] != -1)
1920
return dp[dice][prev][runs];
20-
21+
2122
long ans = 0;
2223
int[] temp = rollMax;
2324
for(int i = 1; i <= 6; i++)
2425
{
25-
if(prev != 0 && i == prev && rollMax[i-1] <= runs)
26+
if(prev != 0 && i == prev && rollMax[i-1] <= runs)
2627
continue;
27-
if(i == prev)
28+
if(i == prev)
2829
ans = (ans + helper(n, dice + 1, i, rollMax, runs + 1)) % mod;
2930
else
3031
ans = (ans + helper(n, dice + 1, i, rollMax, 1)) % mod;
3132
}
32-
33+
3334
dp[dice][prev][runs] = ans;
3435
return ans;
35-
}
36-
}
36+
}
37+
}

0 commit comments

Comments
 (0)