# 剑指Offer（2）6-10题

xiaoxiao2021-02-28  36

## 第6题：旋转数组的最小数字

public class Solution { public int findMin(int[] arr,int left, int right){ while(left < right){ int mid = left + (right - left)/2; if(arr[mid] > arr[right]){ left = mid+1; } else{ right = mid; } } return arr[left]; } public int minNumberInRotateArray(int [] array) { if(array.length == 0){ return 0; } int res; res = findMin(array, 0, array.length-1); return res; } }

## 第7题：裴波那切数列

public class Solution { public int Fibonacci(int n) { int[] res = {0,1}; if(n < 2) { return res[n]; } int fibNMinusOne = 1; int fibNMinusTwo = 0; int fibN = 0; for(int i = 2;i <= n; i++) { fibN = fibNMinusOne + fibNMinusTwo; fibNMinusTwo = fibNMinusOne; fibNMinusOne = fibN; } return fibN; } }

## 第8题：跳台阶

public class Solution { public int JumpFloor(int target) { if(target == 1){ return 1; }else if (target == 2){ return 2; } return JumpFloor(target - 1) + JumpFloor(target - 2); } }

## 第9题：变态跳台阶

public class Solution { public int JumpFloorII(int target) { //每个台阶只有跳或者不跳2种选择，最后一个台阶必须跳 //所以一共有2的n-1次方种选择 return 1<<--target; } }

## 第10题：矩形覆盖

public class Solution { public int RectCover(int target) { if(target < 1){ return 0; } if(target == 1){ return 1; } else if(target == 2){ return 2; } else{ return RectCover(target - 1) + RectCover(target - 2); } } }