Skip to content

Instantly share code, notes, and snippets.

@adamkorg
Created September 27, 2019 14:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adamkorg/a4a4250409a948e13995b5c57e6f99dc to your computer and use it in GitHub Desktop.
Save adamkorg/a4a4250409a948e13995b5c57e6f99dc to your computer and use it in GitHub Desktop.
Leetcode 62: Unique Paths - binomial coefficient
#include <iostream>
using namespace std;
double factorial(int n) {
int fact = 1;
for (int i=2; i<=n; ++i)
fact *= i;
return fact;
}
int uniquePath(int m, int n) {
if (m==0 || n==0)
return 0;
int routes = factorial((m-1)+(n-1))/(factorial(m-1)*factorial(n-1));
return routes;
}
int main() {
cout << uniquePath(23,12) << "\n";
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment