题解 | #走方格的方案数#,看懂了大佬的,没能理解起来
走方格的方案数
http://www.nowcoder.com/practice/e2a22f0305eb4f2f9846e7d644dba09b
import java.util.Scanner;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main2 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
// 注意 hasNext 和 hasNextLine 的区别
while (in.hasNextInt()) { // 注意 while 处理多个 case
int a = in.nextInt();
int b = in.nextInt();
System.out.println(getResult(a,b));
}
}
private static int getResult(int a, int b) {
if (a == 1 || b == 1){
return a + b;
}
return getResult(a - 1,b) + getResult(a,b - 1);
}
}