Skip to content

Commit

Permalink
Create 青蛙上台阶.js
Browse files Browse the repository at this point in the history
  • Loading branch information
Rain120 authored May 30, 2018
1 parent becf85c commit a23a03f
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions 青蛙上台阶.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* 题目描述: 一只青蛙一次最多可以跳上m级台阶。求该青蛙跳上一个n级的台阶总共有多少种跳法。
* f(n) = f( n - 1) + f( n -2) + ... + f( n - m)
* f(n - 1) = f( n -2) + ... + f( n - 1 - m)
**/
var jumpFloor = function(n, m) {
if (n > m){
return 2 * jumpFloor(n - 1, m) - jumpFloor(n - m - 1, m);
    }
if (n === 1) {
return 1;
} else {
return 2 * jumpFloor(n - 1, n);
}
}

0 comments on commit a23a03f

Please sign in to comment.