9、变态跳台阶
一只青蛙一次可以跳上1级台阶,也可以跳上2级……它也可以跳上n级。求该青蛙跳上一个n级的台阶总共有多少种跳法。
===========Python=========
# -*- coding:utf-8 -*- class Solution: def jumpFloorII(self, number): # write code here return 2 ** (number - 1)
=============Java===========
public class Solution { public int JumpFloorII(int target) { int[] dp = new int[target]; for (int i = 0; i < target; i++) { dp[i] = 1; } for (int i = 1; i < target; i++) { for (int j = 0; j < i; j++) { dp[i] += dp[j]; } } return dp[target-1]; } }