diff options
author | crupest <crupest@outlook.com> | 2020-09-26 00:46:59 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2020-09-26 00:46:59 +0800 |
commit | 39b8161912c4c271ff94bf610f36dc45c76a2775 (patch) | |
tree | 2d06ae64c9c535c6bce5b65339d258646bdd8fd8 /works | |
parent | b102b7a14354f5f60ff76d5fc993326d3e6e1555 (diff) | |
download | crupest-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.cpp | 25 |
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; + } +}; |