JZ47 求1+2+3+...+n

本文最后更新于:2022年4月9日 中午

image-20211010150659817

Solution

1
2
3
4
5
6
7
8
class Solution {
public:
int Sum_Solution(int n) {
int sum = n;
bool x = (n > 0) && (sum += Sum_Solution(n-1));
return sum;
}
};

方法二:

1
2
3
4
5
6
7
class Solution {
public:
int Sum_Solution(int n) {
bool a[n][n+1];
return sizeof(a) >>1;
}
};

本博客所有文章除特别声明外,均采用 CC BY-SA 4.0 协议 ,转载请注明出处!