File tree 1 file changed +38
-0
lines changed
1 file changed +38
-0
lines changed Original file line number Diff line number Diff line change
1
+ ##==================================
2
+ ## Leetcode
3
+ ## Student: Vandit Jyotindra Gajjar
4
+ ## Year: 2020
5
+ ## Problem: 62
6
+ ## Problem Name: Unique Paths
7
+ ##===================================
8
+ #A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below).
9
+ #
10
+ #The robot can only move either down or right at any point in time.
11
+ #
12
+ #The robot is trying to reach the bottom-right corner of the grid (marked 'Finish' in the diagram below).
13
+ #
14
+ #How many possible unique paths are there?
15
+ #
16
+ #Above is a 7 x 3 grid. How many possible unique paths are there?
17
+ #
18
+ #Example 1:
19
+ #
20
+ #Input: m = 3, n = 2
21
+ #Output: 3
22
+ #Explanation:
23
+ #From the top-left corner, there are a total of 3 ways to reach the bottom-right corner:
24
+ #1. Right -> Right -> Down
25
+ #2. Right -> Down -> Right
26
+ #3. Down -> Right -> Right
27
+ #
28
+ #Example 2:
29
+ #
30
+ #Input: m = 7, n = 3
31
+ #Output: 28
32
+ class Solution :
33
+ def uniquePaths (self , m , n ):
34
+ tmp = [[1 for j in range (m )] for i in range (n )] #Create a 2d matrix of m column and n row, also filling row and column value by 1
35
+ for i in range (1 , n ): #Loop through n
36
+ for j in range (1 , m ): #Loop through m
37
+ tmp [i ][j ] = tmp [i ][j - 1 ] + tmp [i - 1 ][j ] #Update tmp [i][j] by adding previous row's and column's value respectively
38
+ return tmp [n - 1 ][m - 1 ] #Return tmp value which will be output of total unique Paths.
You can’t perform that action at this time.
0 commit comments