Leetcode-LCR 126 斐波那契数

本题答案需要取模 1e9+7(1000000007)

定义一个变量 = 1000000007,答案%变量,完整题目要求

HashMap方法

java 复制代码
class Solution {
    private Map<Integer,Integer> storeMap = new HashMap();
    public int fib(int n) {
        int constant = 1000000007;
        if(n==0){
            return 0;
        }
        if(n==1){
            return 1;
        }
         if(null != storeMap.get(n)){
            return storeMap.get(n);
        }else{
            int result = fib(n - 1) + fib(n - 2);
            result = result % constant;
            storeMap.put(n,result);
            return result;
        }
    }
}
相关推荐
文丑颜不良啊2 小时前
LeetCode2321~2340题目解析
java·leetcode
青少儿编程课堂3 小时前
蓝桥杯青少组图形化 STEMA 省考(报名倒计时·11/22开考)+ 全国青少年信息素养大赛 2026—2027赛季 + 电子学会图形化考级:校园华容道大闯关
c++·python·算法·bfs·信息学竞赛
在猴站学算法4 小时前
(《统计学习方法》(第2版) 李航)第2章 感知机算法
学习·算法·机器学习·统计学习
Rainmicro4 小时前
【无标题】
java·数据库·算法
NEFU_Jyj14 小时前
牛客周赛R168
算法
文丑颜不良啊21 小时前
LeetCode2221~2240题目解析
java·leetcode
Navigator_Z21 小时前
LeetCode //C - 1317. Convert Integer to the Sum of Two No-Zero Integers
c语言·算法·leetcode
D e re k ZH1 天前
C++ 标准库算法全景指南
数据结构·c++·算法