思路:题目要求1+...+n,不能用循环和乘除法,条件语句,思路是用递归实现,即sum(n) = sum(n-1) + n
代码:
public class Solution {
public int Sum_Solution(int n) {
return solution(n);
}
static int solution(int n){
if(n == 1){
return 1;
}
int sum = 0;
sum = solution(n-1) + n;
return sum;
}
}
end