-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLeetCode062_Unique_Paths.cpp
More file actions
48 lines (38 loc) · 905 Bytes
/
LeetCode062_Unique_Paths.cpp
File metadata and controls
48 lines (38 loc) · 905 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
class Solution {
public:
int uniquePaths(int m, int n) {
int result[m][n] = {0};
for(int i = 0; i < m; i++)
{
result[i][0] = 1;
}
for(int i = 0; i < n; i++)
{
result[0][i] = 1;
}
for(int i = 1; i < m; i++)
{
for(int j = 1; j < n; j++)
{
result[i][j] = result[i-1][j] + result[i][j-1];
}
}
return result[m-1][n-1];
}
};
/*
class Solution {
public:
int uniquePaths(int m, int n) {
double count = 1;
double Denominator = 1;
int small_num = m > n ? n : m;
for(int i = 1; i < small_num; i++)
{
count *= m+n-i-1;
Denominator *= i;
}
return (int)(count/Denominator);
}
};
*/