求1+2+3.。。。n的和

思路:

利用递归累加,逻辑运算符的短路运算。

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

 

posted @ 2019-07-20 10:58  Austin_anheqiao  阅读(253)  评论(0编辑  收藏  举报