Leetcode 62 Solution

This article provides solution to leetcode question 62 (unique-paths)

https://leetcode.com/problems/unique-paths

Solution

class Solution {
public:
    int uniquePaths(int m, int n) {
        int m2 = max(m - 1, n - 1);
        int n2 = min(m - 1, n - 1);

        int64_t a = 1;
        int64_t b = 1;

        for (int i = 0; i < n2; i++)
        {
            a *= (m + n - 2 - i);
            b *= i + 1;
        }

        return a / b;
    }
};