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

Commit2f34d85

Browse files
Lintcode/src/chapter4_DynamicProgrammingI/UniquePaths.java
1 parentdaa7898 commit2f34d85

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
packagechapter4_DynamicProgrammingI;
2+
3+
importutils.CommonUtils;
4+
5+
publicclassUniquePaths {
6+
7+
/**
8+
* @param n, m: positive integer (1 <= n ,m <= 100)
9+
* @return an integer
10+
*/
11+
publicstaticintuniquePaths(intm,intn) {
12+
// write your code here
13+
int[][]ways =newint[m][n];
14+
//initialize row 0
15+
for(inti =0;i <n;i++)ways[0][i] =1;
16+
17+
//initialize col 0
18+
for(inti =0;i <m;i++)ways[i][0] =1;
19+
20+
for(inti =1;i <m;i++){
21+
for(intj =1;j <n;j++){
22+
ways[i][j] =ways[i-1][j] +ways[i][j-1];
23+
}
24+
}
25+
26+
CommonUtils.printMatrix(ways);
27+
returnways[m-1][n-1];
28+
}
29+
30+
31+
publicstaticvoidmain(String...strings){
32+
System.out.print(uniquePaths(2,62));
33+
}
34+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp