My java solution using the knowledge of permutation and combination

  • 0
    public class Solution {
        public int uniquePaths(int m, int n) {
            if(m==0||n==0) return 0;
            if(m==1||n==1) return 1;
            long result = 1;
            if(m<n) {int t=m; m=n; n=t;}
            for(int i=0; i<n-1; i++)
            	result *= n-2+m--;
            for(int i=1; i<=n-1; i++)
            	result /= i;
            return (int)result;

Log in to reply

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