forked from PriyankaKhire/ProgrammingPracticePython
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClimbing Stairs.py
More file actions
42 lines (37 loc) · 1.11 KB
/
Climbing Stairs.py
File metadata and controls
42 lines (37 loc) · 1.11 KB
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# Climbing Stairs
# https://leetcode.com/problems/climbing-stairs/
class Solution(object):
def initialEdgeCases(self, n):
if(n==0):
return 1
if(n==1):
return 1
if(n==2):
return 2
return "None"
def fillMatrix(self, n):
matrix =[[0 for col in range(n+1)] for row in range(n+1)]
row = 0
col = 0
startCol = 0
while(startCol < n+1):
if(row == col or col == row+1):
matrix[row][col] = 1
else:
matrix[row][col] = matrix[row][col-1] + matrix[row+2][col]
row = row+1
col = col+1
if(col == n+1):
startCol = startCol+1
row = 0
col = startCol
return matrix[0][n]
def climbStairs(self, n):
initial = self.initialEdgeCases(n)
if(initial != "None"):
return initial
return self.fillMatrix(n)
"""
:type n: int
:rtype: int
"""