aboutsummaryrefslogtreecommitdiff
path: root/works
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2020-09-26 00:46:59 +0800
committercrupest <crupest@outlook.com>2020-09-26 00:46:59 +0800
commit39b8161912c4c271ff94bf610f36dc45c76a2775 (patch)
tree2d06ae64c9c535c6bce5b65339d258646bdd8fd8 /works
parentb102b7a14354f5f60ff76d5fc993326d3e6e1555 (diff)
downloadcrupest-39b8161912c4c271ff94bf610f36dc45c76a2775.tar.gz
crupest-39b8161912c4c271ff94bf610f36dc45c76a2775.tar.bz2
crupest-39b8161912c4c271ff94bf610f36dc45c76a2775.zip
import(solutions): Add problem 62 .
Diffstat (limited to 'works')
-rw-r--r--works/solutions/cpp/62.cpp25
1 files changed, 25 insertions, 0 deletions
diff --git a/works/solutions/cpp/62.cpp b/works/solutions/cpp/62.cpp
new file mode 100644
index 0000000..042b274
--- /dev/null
+++ b/works/solutions/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;
+ }
+};