時(shí)間限制:1秒 空間限制:32768K
題目描述
求1+2+3+...+n,要求不能使用乘除法、for、while、if、else、switch、case等關(guān)鍵字及條件判斷語句(A?B:C)。
我的代碼
class Solution {
public:
int Sum_Solution(int n) {
int ans=n;
ans && (ans+=Sum_Solution(n-1));
return ans;
}
};
運(yùn)行時(shí)間:5ms
占用內(nèi)存:472k