题目描述
求1+2+…+n,要求不能使用乘除法、for、while、if、else、switch、case等关键字及条件判断语句(A?B:C)。
样例
求1+2+…+n,要求不能使用乘除法、for、while、if、else、switch、case等关键字及条件判断语句(A?B:C)。
算法1
C++ 代码
```
class Solution {
public:
int getSum(int n) {
int x = n;
x > 0 && (x += getSum(n - 1));
return x;
}
};