题解 | #求1+2+3+...+n#
求1+2+3+...+n
https://www.nowcoder.com/practice/7a0da8fc483247ff8800059e12d7caf1
public class Solution { public int Sum_Solution(int n) { if (n >= 0) { return n + Sum_Solution(n - 1); } return 0 ; } }
解题思想:递归
#算法##算法笔记#求1+2+3+...+n
https://www.nowcoder.com/practice/7a0da8fc483247ff8800059e12d7caf1
public class Solution { public int Sum_Solution(int n) { if (n >= 0) { return n + Sum_Solution(n - 1); } return 0 ; } }
解题思想:递归
#算法##算法笔记#相关推荐