Skip to content

Commit c59442b

Browse files
committed
add climbing-stairs
1 parent 1b0b0b1 commit c59442b

File tree

2 files changed

+29
-6
lines changed

2 files changed

+29
-6
lines changed

climbing-stairs/rivkode.py

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,41 @@
11
# Time Complexity O(n)
22
# - traversing for loop takes O(n)
3+
# - same with 피보나치
34
# Space Complexity O(n)
45
# - appending for loop it takes O(n)
56

67
class Solution:
7-
def climbStairs(self, n: int) -> int:
8-
stage = [1, 2, 3]
98

10-
for i in range(3, 45):
11-
value = stage[i - 1] + stage[i - 2]
12-
stage.append(value)
9+
def climbStairs(self, n):
10+
"""
11+
:type n: int
12+
:rtype: int
13+
"""
1314

14-
return stage[n - 1]
15+
map = {1:1, 2:2}
16+
17+
18+
for i in range(3, n + 1):
19+
map[i] = map[i-1] + map[i-2]
20+
21+
return map[n]
22+
23+
24+
# def climbStairs(self, n: int) -> int:
25+
# stage = [1, 2, 3]
26+
27+
# for i in range(3, 45):
28+
# value = stage[i - 1] + stage[i - 2]
29+
# stage.append(value)
30+
31+
# return stage[n - 1]
1532

1633
if __name__ == "__main__":
1734
solution = Solution()
1835
result = solution.climbStairs(5)
1936
print(result)
2037

38+
39+
40+
41+

valid-anagram/rivkode.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,5 @@ def isAnagram(self, s: str, t: str) -> bool:
6464

6565
result = solution.isAnagram(s, t)
6666
print(result)
67+
68+

0 commit comments

Comments
 (0)