dp solution in java


  • 0
    U

    /time complexity is O(rc)/
    '''
    class Solution {
    public int uniquePaths(int r, int c) {
    int[][] arr=new int[r][c];
    arr[0][0]=1;
    for(int i=0;i<r;i++){
    for(int j=0;j<c;j++){
    if(j>0){
    arr[i][j]+=arr[i][j-1];
    }
    if(i>0){
    arr[i][j]+=arr[i-1][j];
    }
    }
    }
    return arr[r-1][c-1];
    }
    }

    '''


Log in to reply
 

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