题解 | #跳台阶#
跳台阶
https://www.nowcoder.com/practice/8c82a5b80378478f9484d87d1c5f12a4
import java.util.*;
public class Solution {
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param number int整型
* @return int整型
*/
public int jumpFloor (int number) {
// write code here
if (number == 0) {
return 0;
}
if (number == 1) {
return 1;
}
int lastBefore = 1, last = 1, current = 1;
// 当前跳台阶怎么跳
for (int i = 2; i <= number; i++) {
current = last + lastBefore;
lastBefore = last;
last = current;
}
return current;
}
}
查看16道真题和解析
