From eae79864963d0fd9634212fa6690c36c28d2aa5d Mon Sep 17 00:00:00 2001 From: Omooo <869759698@qq.com> Date: Tue, 30 Jun 2020 08:52:17 +0800 Subject: [PATCH] =?UTF-8?q?Create=20=E9=80=92=E5=BD=92=E7=9B=B8=E5=85=B3.m?= =?UTF-8?q?d?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- blogs/Algorithm/剑指 Offer/递归相关.md | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 blogs/Algorithm/剑指 Offer/递归相关.md diff --git a/blogs/Algorithm/剑指 Offer/递归相关.md b/blogs/Algorithm/剑指 Offer/递归相关.md new file mode 100644 index 0000000..fd711ab --- /dev/null +++ b/blogs/Algorithm/剑指 Offer/递归相关.md @@ -0,0 +1,26 @@ +--- +递归相关 +--- + +#### [10- I. 斐波那契数列](https://leetcode-cn.com/problems/fei-bo-na-qi-shu-lie-lcof/) + +```java +class Solution { + + public int fib(int n) { + if (n == 0 || n == 1) { + return n; + } + int start = 0; + int end = 1; + int result = 0; + for (int i = 2; i <= n; i++) { + result = (start + end) % 1000000007; + start = end; + end = result; + } + return result; + } +} +``` +