Easiest C++ Solution, O(min(A, B)) complexity


#1

Please let me know if it can get any better…

int Solution::uniquePaths(int A, int B) {
    int sum = A+B-2;
    int ret = 1;
    int mx = max(A, B);
    for (int i=mx; i<=sum; i++){
        ret *= i;
        ret /= (i-mx+1);
    }
    return ret;
}