public static int step(int n){ if(n < 1){ throw new IllegalArgumentException("n不能小于1。"); } if(n == 1 || n == 2){ return n; } return step(n - 1) + step(n - 2); }
有n步台阶,一次只能上1步或2步,共有多少种走法?
原文:https://www.cnblogs.com/kaka-qiqi/p/14537942.html