LeetCode/DP심화

509. Fibonacci Number

hyunkookim 2025. 1. 2. 15:59

509. Fibonacci Number

 

class Solution:
    def fib(self, n: int) -> int:
        if n<=1:
            return n

        dp = [0] * (n+1)
        dp[0]= 0
        dp[1]= 1

        for i in range(2, n+1):
            dp[i] = dp[i-1] + dp[i-2]
        
        return dp[n]

'LeetCode > DP심화' 카테고리의 다른 글

931. Minimum Falling Path Sum  (0) 2025.01.03
740. Delete and Earn  (0) 2025.01.02
221. Maximal Square ★  (0) 2024.12.31
188. Best Time to Buy and Sell Stock IV  (2) 2024.12.31
123. Best Time to Buy and Sell Stock III ★★★  (0) 2024.12.31