题解 | #跳台阶#
跳台阶
http://www.nowcoder.com/practice/8c82a5b80378478f9484d87d1c5f12a4
看了别人的题解,我就是一个另类,先求出跳完台阶要跳多少次1阶和跳多少次2阶,然后排列组合。组后将结果加起来。
public static int jumpFloor(int target) { int count = 0; int x,y; for ( x = 0;x <= target;x++){ if ((target-x) % 2 == 0){ y = (target -x)/2; if (x<= y){ count += pailiexuhe(x+y,y)/pailiexuhe(x,0); }else { count += pailiexuhe(x+y,x)/pailiexuhe(y,0); } } } return count; } public static long pailiexuhe(int start,int end){ //暂时省略判断参数的合法性 long sum = 1; while( start > end){ sum = sum * start--; } return sum; }