剑指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;
}
};
链接: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;
}
};