Python O(n^2) Dp solution


#1

Commentclass Solution:
# @param A : integer
# @param B : integer
# @return an integer

def uniquePaths(self, A, B):
    dp=[]
    for i in range(A+1):
        dp.append([])
        for j in range(B+1):
            dp[-1].append(0)
    i=A
    j=B
    while(i>0):
        dp[i][B]=1
        i-=1
    while(j>0):
        dp[A][j]=1
        j-=1
    i=A-1
    j=B-1
    
    while(i>0):
        j=B-1
        while(j>0):
            dp[i][j]=dp[i+1][j]+dp[i][j+1]
            j-=1
        i-=1
    return dp[1][1] body goes here.