-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathL62.java
More file actions
29 lines (28 loc) · 872 Bytes
/
L62.java
File metadata and controls
29 lines (28 loc) · 872 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
class Solution62 {
class Solution {
/**
* 62. Unique Paths https://leetcode.com/problems/unique-paths/description/
*
* @param m Number of rows
* @param n Number of columnes
* @return Number of paths to end of grid
* @timeComplexity O(m * n)
* @spaceComplexity O(m * n)
*/
public int uniquePaths(int m, int n) {
int table[][] = new int[m][n];
for (int i = 0; i < m; i++) {
table[i][0] = 1;
}
for (int i = 0; i < n; i++) {
table[0][i] = 1;
}
for (int i = 1; i < m; i++) {
for (int j = 1; j < n; j++) {
table[i][j] = table[i - 1][j] + table[i][j - 1];
}
}
return table[m - 1][n - 1];
}
}
}