题解 | #斐波那契数列#

斐波那契数列

http://www.nowcoder.com/practice/c6c7742f5ba7442aada113136ddea0c3

记录

import java.util.*;
class Solution {
    public int Fibonacci(int n) {
        if (n == 0 || n == 1){
            return n;
        }
        int one = 0,two = 1;
        int sum = 0;
        for (int i = 1; i < n; i++){
            sum = (one + two) % 1000000007;
            one = two;
            two = sum;
        }
        return sum;

    }
    public static void main(String[] args){
        Solution s = new Solution();
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int re = s.Fibonacci(n);
        System.out.println(re);
    }


}
全部评论

相关推荐

10-17 13:54
上海大学 运营
雾凇岛:这还说什么了,冲了兄弟们
点赞 评论 收藏
分享
双尔:你就写拥有ai开发经历,熟练运用提示词,优化ai,提高ai回答质量
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务