面试题9:题目二青蛙跳台阶

来源:互联网 发布:软件销售代理协议 编辑:程序博客网 时间:2024/05/21 17:19
public class Solution {
    public int JumpFloor(int target) {
        int a=1;//一个台阶一种跳法
        int b=2;//两个台阶两种
        int c=0;
        if(target==1){
            c=1;
        }else if(target==2){
            c=2;
        }else{
            for(int i=3;i<=target;i++){
                c=a+b;
                a=b;
                b=c;
            }
        }
        return c;
    }
}
原创粉丝点击