思路
本题不允许使用乘除运算符,还要结构语句,剩下的运算只有位运算和逻辑运算。
代码
public class Solution {
public int Sum_Solution(int n) {
int sum = n;
boolean ans = (n>0)&&((sum+=Sum_Solution(n-1))>0);
return sum;
}
}

本题不允许使用乘除运算符,还要结构语句,剩下的运算只有位运算和逻辑运算。
public class Solution {
public int Sum_Solution(int n) {
int sum = n;
boolean ans = (n>0)&&((sum+=Sum_Solution(n-1))>0);
return sum;
}
}