剑指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;
    }
};
posted @ 2020-03-15 12:48  景云ⁿ  阅读(99)  评论(0编辑  收藏  举报