跳台阶

作者: Crazy_Bear | 来源:发表于2020-07-29 12:00 被阅读0次
    • 一只青蛙一次可以跳上1级台阶,也可以跳上2级。求该青蛙跳上一个n级的台阶总共有多少种跳法(先后次序不同算不同的结果)。
    • 斐波那契数列
    • C++ 代码
    public class Solution {
        public int JumpFloor(int target) {
            int pre = 0;
            int cur = 1;
            for(int i = 1; i<=target; i++) {
                int tmp = cur;
                cur += pre;
                pre = tmp;
            }
            return cur;
        }
    }
    

    相关文章

      网友评论

          本文标题:跳台阶

          本文链接:https://www.haomeiwen.com/subject/yxjjlktx.html