A clear C++ approach. 2ms.


  • 0
    Y
    class Solution {
    public:
        int uniquePaths(int m, int n) {
            double s=1,s1=1;
            if(m==1||n==1) return 1;
            int max=(m>n)?(m-1):(n-1);
            int min=(m<n)?(m-1):(n-1);
            for(int i=max+1;i<=max+min;i++) {s*=i;s1*=i-max;}
        	return s/s1;
        }
    };

Log in to reply
 

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