文章目录
- AcWing 84. 求1+2+…+n
- AC代码
AcWing 84. 求1+2+…+n
本题链接:AcWing 84. 求1+2+…+n
本博客给出本题截图:
AC代码
代码:
class Solution { public: int getSum(int n) { int res = n; n > 0 && (res += getSum(n - 1)); return res; } };
本题链接:AcWing 84. 求1+2+…+n
本博客给出本题截图:
代码:
class Solution { public: int getSum(int n) { int res = n; n > 0 && (res += getSum(n - 1)); return res; } };