假设你正在爬楼梯。需要 n 阶你才能到达楼顶。
每次你可以爬 1 或 2 个台阶。你有多少种不同的方法可以爬到楼顶呢?
import java.util.*;
public class Solution {
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
* @param n int整型
* @return int整型
*/
public int climbStairs (int n) {
// write code here
if(n == 1)return 1;
else if(n == 2)return 2;
else{
return climbStairs(n - 1) + climbStairs(n - 2);
}
}
}