LeetCode 筆記 - 509. Fibonacci Number Posted on 2022-07-23題目在此 509. Fibonacci Number請計算費氏數列的結果解題思維就簡單 Dynamic programming 避免重複的計算即可剩下就跟著定義實作即可程式碼123456789101112class Solution: count = [inf] * 31 count[0] = 0 count[1] = 1 def fib(self, n: int) -> int: if self.count[n] != inf: return self.count[n] result = self.fib(n - 1) + self.fib(n - 2) self.count[n] = result return result也許你也會想看看LeetCode 筆記 - 268. Missing NumberLeetCode 筆記 - 567. Permutation in StringLeetCode 筆記 - 9. Palindrome Number