0ms Java 10 line code


  • 10
    public int uniquePaths(int m, int n) {
        int smaller = m>n ? n-1 : m-1;
        int totalsteps = m+n-2;
        long result = 1;
        for (int counter = 1; counter<=smaller; counter++){
            result *= totalsteps--;
            result /= counter;
        }
        return (int)result;
    }
    

    Basically it is math: select m (or n) from [(m-1)+(n-1)]


Log in to reply
 

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