题解 | 数楼梯
数楼梯
https://www.nowcoder.com/practice/c7e5f164fa5d471f8f83c90fe4ee3f05
import java.util.Scanner;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
// 注意 hasNext 和 hasNextLine 的区别
int count = in.nextInt();
if(count==0){
System.out.println(0);
return;
}else if(count==1){
System.out.println(1);
return;
}
long[] dp = new long[count];
dp[0] = 1;
dp[1] = 2;
for(int i = 2; i < count; i++){
dp[i] = (dp[i-1] + dp[i-2])%998244353;
}
long res = dp[count-1];
System.out.println(res);
}
}


查看3道真题和解析