假设一只青蛙每次可以跳1步或2步,台阶总共有n步,总共有多少种跳法?
public class StepAlgorithm {
public static void main(String[] args) {
System.out.println(getAllSteps(5));
}
public static int getAllSteps(int n){
if(n == 1){
return 1;
}
if(n == 2){
return 2;
}
return getAllSteps(n - 1) + getAllSteps(n - 2);
}
}