Skip to content

Commit

Permalink
Create 017 Unique Paths.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
atharv-patil authored Jun 13, 2023
1 parent e05fcd7 commit 8580dda
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions 017 Unique Paths.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include <bits/stdc++.h>


int uniquePaths(int m, int n) {

// vector<vector<int>>a(m,vector<int>(n,0));

// for (int i=0;i<n;i++)
// a[0][i] = 1;

// for (int i=1;i<m;i++)
// {
// for (int j=0;j<n;j++)
// {
// a[i][j] += a[i-1][j];
// if (j)
// a[i][j]+=a[i][j-1];
// }
// }
// return a[m-1][n-1];

// using PnC
int N = n+m-2;
int r = m-1;
double res = 1;

for (int i=1;i<=r;i++)
res = res*(N-r+i)/i;
return (int)res;

}

0 comments on commit 8580dda

Please sign in to comment.