Skip to content

Commit b558ba8

Browse files
authored
Merge pull request larissalages#151 from ganm0/leetcode#62
Added solution to Leetcode#62 Unique Paths
2 parents 197d172 + 06451d3 commit b558ba8

File tree

1 file changed

+23
-0
lines changed
  • leetcode/cpp/dynamic programming

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+
//Unique Paths
2+
3+
class Solution {
4+
public:
5+
long long comb(int n,int k){
6+
long long arr[n+1][k+1];
7+
for(int i=0;i<=n;i++){
8+
for(int j=0;j<=min(i,k);j++){
9+
if(j == 0 || j == i){
10+
arr[i][j] = 1;
11+
}
12+
else{
13+
arr[i][j] = arr[i-1][j]+arr[i-1][j-1];
14+
}
15+
}
16+
}
17+
return arr[n][k];
18+
}
19+
20+
int uniquePaths(int m, int n) {
21+
return comb(m+n-2,min(m,n)-1);
22+
}
23+
};

0 commit comments

Comments
 (0)