求1+2+3+...+n,要求不能使用乘除法、for、while、if、else、switch、case等关键字及条件判断语句(A?B:C)

来源:互联网 发布:世界地图历史演变软件 编辑:程序博客网 时间:2024/05/17 22:13
class Solution {public:    int Sum_Solution(int n) {       int ans = n;        ans && (ans += Sum_Solution(n - 1));        return ans;    }};
分析:&& 运算,当前面为假时,后面自动不算。
阅读全文
0 0