描述
求1+2+3+…+n,要求不能使用乘除法、for、while、if、else、switch、case等关键字及条件判断语句(A?B:C)。
示例1
输入: 5
返回值: 15
public class Solution {
public int Sum_Solution(int n) {
int sum = n;
// bool x只是为了不报错
boolean x = n > 1 && (sum += Sum_Solution(n-1)) > 0;
return sum;
}
}
861

被折叠的 条评论
为什么被折叠?



