解题思路

此题考点为高中数学中的等差数列求和,Sn=n(a1+an)/2
故直接return n*(n+1)/2

代码

class Solution {
public:
int sumNums(int n) {
return n*(n+1)/2;
}
};