题目:求1+2+3+...+n,要求不能使用乘除法、for、while、if、else、switch、case等关键字及条件判断语句(A?B:C)
思路:递归完事
public class Solution {
public int Sum_Solution(int n) {
return fun(n);
}
public int fun(int n){
if(n==0){
return 0;
}
return n+fun(n-1);
}
}
京公网安备 11010502036488号