얼렁뚱땅 스며드는 Data Science

Algorithm/Daily Coding Tests Challenge

[Leetcode] Easy: Climbing Stairs

Jesip14 2021. 10. 10. 19:02

Description

You are climbing a staircase. It takes n steps to reach the top.

Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?

 

My Solution

class Solution:
    def climbStairs(self, n: int) -> int:
        array = [0] * 46
        array[1] = 1
        array[2] = 2
        
        for i in range(3, 46):
            array[i] = array[i - 1] + array[i - 2]
        
        return array[n]

 

문제 출처 : https://leetcode.com/problems/climbing-stairs/

 

Climbing Stairs - LeetCode

Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.

leetcode.com