题解 | #跳台阶#
跳台阶
http://www.nowcoder.com/practice/8c82a5b80378478f9484d87d1c5f12a4
public class Solution {
/*
n 跳法
1 1
2 2
3 3
4 5
5 8
n 前两个跳法的和
*/
public int jumpFloor(int target) {
ArrayList<Integer> outCome = new ArrayList<>();
outCome.add(0,1);
outCome.add(1,2);
if(target == 0 || target ==1){
return outCome.get(target-1);
}else{
for(int i =2; i < target; i++){
outCome.add(i, outCome.get(i-1) + outCome.get(i-2));
}
return outCome.get(target -1);
}
}
}