Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 1cebeb3

Browse files
authored
Create Find the N-th Value After K Seconds.java
1 parent 55d0ecf commit 1cebeb3

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Solution {
2+
3+
private final int MOD = 1000_000_007;
4+
5+
public int valueAfterKSeconds(int n, int k) {
6+
int[] arr = new int[n];
7+
Arrays.fill(arr, 1);
8+
while (k-- > 0) {
9+
for (int i = 1; i < n; i++) {
10+
arr[i] = (arr[i] + arr[i - 1]) % MOD;
11+
}
12+
}
13+
return arr[n - 1];
14+
}
15+
}

0 commit comments

Comments
 (0)