C++ solution without using long long


  • 0
    P
    class Solution {
    public:
        int uniquePaths(int m, int n) {
            if(m>n) swap(m,n);
            int j = 1,k = n+m-2,prod = 1;
            while(k>n-1){
                prod *= k;
                while(j<=m-1 && prod%j==0){
                    prod/=j;
                    j++;
                }
                k--;
            }
            return prod;
        }
    };

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.