Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit532b766

Browse files
authored
Create Number of Ways to Stay in the Same Place After Some Steps.java
1 parent9ae580a commit532b766

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
classSolution {
2+
3+
privatestaticfinalintMOD =1000_000_007;
4+
5+
publicintnumWays(intsteps,intarrLen) {
6+
arrLen =Math.min(arrLen,steps);
7+
int[][]dp =newint[arrLen][steps +1];
8+
dp[0][0] =1;
9+
for (inti =1;i <=steps;i++) {
10+
for (intj =arrLen -1;j >=0;j--) {
11+
intresult =dp[j][i -1];
12+
if (j >0) {
13+
result = (result +dp[j -1][i -1]) %MOD;
14+
}
15+
if (j <arrLen -1) {
16+
result = (result +dp[j +1][i -1]) %MOD;
17+
}
18+
dp[j][i] =result;
19+
}
20+
}
21+
returndp[0][steps];
22+
}
23+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp