Java 1ms solution, easy, simple


  • 0
    R
    public int uniquePaths(int m, int n) {
        int[][] result = new int[m][n];
        for(int index=0; index<n;index++){
            result[0][index]=1;
        }
        for(int index=0; index<m;index++){
            result[index][0]=1;
        }
        for(int indexY=1; indexY<m;indexY++){
            for(int indexX=1;indexX<n;indexX++){
                result[indexY][indexX]=result[indexY-1][indexX]+result[indexY][indexX-1];
            }
        }
        return result[m-1][n-1];
    }

Log in to reply
 

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