題面509. 斐波那契數 - 力扣(LeetCode)
題解:同2024.9.6 leetcode 70 爬樓梯 (雜湊表/動態規劃) - 樹寶2021 - 部落格園 (cnblogs.com)
class Solution { public: int fib(int n) { unordered_map<int,int> umap; umap.insert({0,0}); umap.insert({1,1}); for(int i = 2; i <= 30; i++) { umap.insert({i,umap[i-1]+umap[i-2]}); } return umap[n]; } };