mirror of
https://github.com/CyC2018/Interview-Notebook.git
synced 2026-10-30 18:23:52 +00:00
Update 64. 求 1+2+3+...+n.md
题目链接改为力扣中的对应题目,题目描述和代码按该题的接口调整。
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
## 题目链接
|
||||
|
||||
[NowCoder](https://www.nowcoder.com/practice/7a0da8fc483247ff8800059e12d7caf1?tpId=13&tqId=11200&tPage=1&rp=1&ru=/ta/coding-interviews&qru=/ta/coding-interviews/question-ranking&from=cyc_github)
|
||||
[Leetcode](https://leetcode.cn/problems/qiu-12n-lcof/)
|
||||
|
||||
## 题目描述
|
||||
|
||||
@@ -17,9 +17,9 @@
|
||||
本题的递归返回条件为 n \<= 0,取非后就是 n \> 0;递归的主体部分为 sum += Sum_Solution(n - 1),转换为条件语句后就是 (sum += Sum_Solution(n - 1)) \> 0。
|
||||
|
||||
```java
|
||||
public int Sum_Solution(int n) {
|
||||
int sum = n;
|
||||
boolean b = (n > 0) && ((sum += Sum_Solution(n - 1)) > 0);
|
||||
public int mechanicalAccumulator(int target) {
|
||||
int sum = target;
|
||||
boolean b = (target > 0) && ((sum += mechanicalAccumulator(target - 1)) > 0);
|
||||
return sum;
|
||||
}
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user