-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUniquePaths.java
More file actions
34 lines (29 loc) · 727 Bytes
/
Copy pathUniquePaths.java
File metadata and controls
34 lines (29 loc) · 727 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package com.gankki.demo.algorithm.leetcode.uniquePaths62;
/**
* 不同路径
*
* @author liuhao
* @date 2020/9/22
*/
public class UniquePaths {
public static void main(String[] args) {
}
/**
* 2020/9/22 22:43 O(m*n) O(m∗n) 空间、时间复杂度都为 m*n
*/
public int uniquePaths1(int m, int n) {
int[][] mn = new int[m][n];
for (int i = 0; i < m ; i++) {
mn[i][0] = 1;
}
for (int i = 0; i < n ; i++) {
mn[0][i] = 1;
}
for (int i = 1; i < m; i++) {
for (int j = 1; j < n ; j++) {
mn[i][j] = mn[i - 1][j] + mn[i][j - 1];
}
}
return mn[m - 1][n - 1];
}
}