题解 | #跳台阶#
跳台阶
http://www.nowcoder.com/practice/8c82a5b80378478f9484d87d1c5f12a4
/**
*
* @param number int整型
* @return int整型
*/
int jumpFloor(int number ) {
// write code here
int a = 1 , b = 1, c = 1;
for(int i = 2;i<=number;i++ ){
c = a+b;
a = b;
b = c;
}
return c;
}窃以为当台阶只有0级或1级时,都应该只有一种跳法,不能认为0级台阶的跳法为0,因为不用跳也是一种跳法,因此当输入值为0或1时直接返回1,输入值大于1时才进入循环。
SHEIN希音公司福利 294人发布
