0 ms Simple Java solution


  • 0
    K
    public class Solution {
        public int uniquePaths(int m, int n) {
        // Compute C((m-1)+(n-1), (m-1))
            m--; n--;
            int mn = m + n;
            double ans = 1;
            for(int i=0;i<m;i++)
                ans = ans * ((double)(mn - i) / (m-i));
            return (int)Math.round(ans);
        }
    }

Log in to reply
 

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