diff options
Diffstat (limited to 'store/works/solutions/leetcode/cpp/62.cpp')
-rw-r--r-- | store/works/solutions/leetcode/cpp/62.cpp | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/store/works/solutions/leetcode/cpp/62.cpp b/store/works/solutions/leetcode/cpp/62.cpp new file mode 100644 index 0000000..744a0d3 --- /dev/null +++ b/store/works/solutions/leetcode/cpp/62.cpp @@ -0,0 +1,25 @@ +#include <utility>
+
+class Solution
+{
+public:
+ // C(m + n - 2, m - 1)
+ int uniquePaths(int m, int n)
+ {
+ if (m < n)
+ std::swap(m, n);
+
+ long long result = 1;
+ for (int i = m; i <= m + n - 2; i++)
+ {
+ result *= i;
+ }
+
+ for (int i = 2; i <= n - 1; i++)
+ {
+ result /= i;
+ }
+
+ return result;
+ }
+};
|