62. Unique Paths - LeetCode Solution


Array Dynamic Programming

Python Code:

class Solution:
    def uniquePaths(self, m: int, n: int) -> int:
        
        d = [[0] * m] * n
        
        for i in range(n):
            for j in range(m):
                if( i==0 or j==0 ):                  
                    d[i][j] = 1
                else:                                  
                    d[i][j] = (d[i-1][j] + d[i][j-1])
        return d[-1][-1]
        


Comments

Submit
0 Comments
More Questions

1176A - Divide it
1527A - And Then There Were K
1618E - Singers' Tour
1560B - Who's Opposite
182B - Vasya's Calendar
934A - A Compatible Pair
1618F - Reverse
1684C - Column Swapping
57C - Array
1713D - Tournament Countdown
33A - What is for dinner
810A - Straight A
1433C - Dominant Piranha
633A - Ebony and Ivory
1196A - Three Piles of Candies
299A - Ksusha and Array
448B - Suffix Structures
1092B - Teams Forming
1166C - A Tale of Two Lands
544B - Sea and Islands
152B - Steps
1174D - Ehab and the Expected XOR Problem
1511A - Review Site
1316A - Grade Allocation
838A - Binary Blocks
1515D - Phoenix and Socks
1624D - Palindromes Coloring
1552F - Telepanting
1692G - 2Sort
1191A - Tokitsukaze and Enhancement