From c7428be1c72cb22fa0d477e34d7957446d5c9703 Mon Sep 17 00:00:00 2001 From: CyC2018 <1029579233@qq.com> Date: Fri, 9 Mar 2018 19:41:32 +0800 Subject: [PATCH] auto commit --- notes/剑指 offer 题解.md | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/notes/剑指 offer 题解.md b/notes/剑指 offer 题解.md index ab081a17..02b4a96e 100644 --- a/notes/剑指 offer 题解.md +++ b/notes/剑指 offer 题解.md @@ -341,24 +341,32 @@ public int pop() { ## 10.1 斐波那契数列 +**题目描述** + +以 O(1) 的时间复杂度求菲波那切数列。 + ```java -private int[] fib = new int[40]; - -public Solution() { - fib[1] = 1; - fib[2] = 2; - for (int i = 2; i < fib.length; i++) { - fib[i] = fib[i - 1] + fib[i - 2]; +public class Solution { + private int[] fib = new int[40]; + public Solution() { + fib[1] = 1; + fib[2] = 2; + for(int i = 2; i < fib.length; i++) { + fib[i] = fib[i - 1] + fib[i - 2]; + } + } + public int Fibonacci(int n) { + return fib[n]; } -} - -public int Fibonacci(int n) { - return fib[n]; } ``` ## 10.2 跳台阶 +**题目描述** + +一只青蛙一次可以跳上1级台阶,也可以跳上2级。求该青蛙跳上一个n级的台阶总共有多少种跳法。 + ```java public int JumpFloor(int target) { if (target == 1) return 1; @@ -374,6 +382,10 @@ public int JumpFloor(int target) { ## 10.3 变态跳台阶 +**题目描述** + +一只青蛙一次可以跳上1级台阶,也可以跳上2级……它也可以跳上n级。求该青蛙跳上一个n级的台阶总共有多少种跳法。 + ```java public int JumpFloorII(int target) { int[] dp = new int[target];