- Notifications
You must be signed in to change notification settings - Fork 625
/
Copy path62.py
27 lines (21 loc) · 818 Bytes
/
62.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
'''
A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below).
The robot can only move either down or right at any point in time. The robot is trying to reach the bottom-right corner of the grid (marked 'Finish' in the diagram below).
How many possible unique paths are there?
'''
classSolution(object):
defuniquePaths(self, m, n):
"""
:type m: int
:type n: int
:rtype: int
"""
dp= [[0for_inrange(n)] for_inrange(m)]
forindexinrange(m):
dp[index][0] =1
forindexinrange(n):
dp[0][index] =1
forindex_iinrange(1, m):
forindex_jinrange(1, n):
dp[index_i][index_j] =dp[index_i-1][index_j] +dp[index_i][index_j-1]
returndp[m-1][n-1]