In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces LeetCode how to find the nth item of the Fibonacci series, which is very detailed and has a certain reference value. Interested friends must read it!
A brief description of the problem
Write a function, enter n, and find the nth term of the Fibonacci series. The Fibonacci series is defined as follows:
F (0) = 0, F (1) = 1F (N) = F (N-1) + F (N-2), where N > 1. The Fibonacci series starts with 0 and 1, and the subsequent Fibonacci number is derived from the addition of the previous two numbers.
The answer needs to be modular 1e9+7 (1000000007). If the initial result is 1000000008, please return 1.
Example
Example 1:
Input: n = 2 output: 1 example 2:
Input: n = 5 output: 5
The train of thought of problem solving
Use dynamic programming to solve the problem
Problem solving procedure
Public class FibTest {public static void main (String [] args) {int n = 5; int a = fib (n); System.out.println ("a =" + a);}
Public static int fib (int n) {if (n = 0) {return 0;} if (n = 1) {return 1;} int [] dp = new int [n + 1]; dp [0] = 0; dp [1] = 1; for (int I = 2; I
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.