From fbffa7e54d5c1f2f4b4ade2f634b14fccffa6281 Mon Sep 17 00:00:00 2001 From: Changhyun Lee Date: Tue, 17 Dec 2024 16:24:07 +0900 Subject: [PATCH] ADD : #230 by heypaprika --- climbing-stairs/heypaprika.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 climbing-stairs/heypaprika.py diff --git a/climbing-stairs/heypaprika.py b/climbing-stairs/heypaprika.py new file mode 100644 index 000000000..051b18546 --- /dev/null +++ b/climbing-stairs/heypaprika.py @@ -0,0 +1,19 @@ +""" +복잡도 : 예상 -> 예상한 이유 + +시간 복잡도 : O(n) -> 배열의 길이 n-2 만큼 반복하므로 +공간 복잡도 : O(n) -> n 길이의 배열 하나를 생성하므로 +""" +class Solution: + def climbStairs(self, n: int) -> int: + if n == 1: + return 1 + elif n == 2: + return 2 + a = [0] * n + a[0] = 1 + a[1] = 2 + for i in range(2, n): + a[i] = a[i-1] + a[i-2] + return a[n-1] +