Created
September 27, 2019 14:48
-
-
Save adamkorg/a4a4250409a948e13995b5c57e6f99dc to your computer and use it in GitHub Desktop.
Leetcode 62: Unique Paths - binomial coefficient
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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