剑指OFFER----面试题64. 求1+2+…+n

链接:https://leetcode-cn.com/problems/qiu-12n-lcof/

代码

class Solution {
public:
    int sumNums(int n) {
        int res = n;
        n > 0 && (res += sumNums(n - 1));
        return res;
    }
};

猜你喜欢

转载自www.cnblogs.com/clown9804/p/12496966.html