int jumpFloor(int number ) { int a = 1, b = 1; for(int i=2; i<=number; i++) { a = a + b; b = a - b; } return a; }
a | b | a=a+b | b=a-b (=a) |
1 | 1 | 2 | 1 |
2 | 1 | 3 | 2 |
3 | 2 | 5 | 3 |
5 | 3 | 8 | 5 |
int jumpFloor(int number ) { int a = 1, b = 1; for(int i=2; i<=number; i++) { a = a + b; b = a - b; } return a; }
a | b | a=a+b | b=a-b (=a) |
1 | 1 | 2 | 1 |
2 | 1 | 3 | 2 |
3 | 2 | 5 | 3 |
5 | 3 | 8 | 5 |