[8 interview questions

To prove safety offer Q8.

Title Description

A frog can jump on a Class 1 level, you can also hop on level 2. The frog jumped seeking a total of n grade level how many jumps (the order of different calculation different results).

Problem-solving ideas

Jumps to this question, as long as only one of the first-order or second order.

  • If the two jumps, the first-order or second-order, it is assumed that the first hop is a first order, the remaining steps are the n-1, F is the jumps (n-1);
  • The first hop is assumed that the second order, the remaining n-2 th is a step, jump method is F (n-2)
  • The total jump method can be derived as: f (n) = f (n-1) + f (n-2)
  • Then the actual situation can be obtained by: a first order only when f (1) = 1, when only two bands may have f (2) = 2

my answer

1
2
3
4
5
6
7
8
9
10
11
大专栏  【面试题8ine">public class  {
public int JumpFloor(int target) {
if(target == 1){
return 1;
}else if(target == 2){
return 2;
}else{
return JumpFloor(target-1) + JumpFloor(target-2);
}
}
}

Guess you like

Origin www.cnblogs.com/lijianming180/p/12348232.html