Skip to content
This repository was archived by the owner on Sep 20, 2023. It is now read-only.

Commit 3e8e872

Browse files
aQuaaQua
aQua
authored and
aQua
committed
873 finish
1 parent ab94fbf commit 3e8e872

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

.vscode/bookmarks.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"path": "$ROOTPATH$/Algorithms/0873.length-of-longest-fibonacci-subsequence/length-of-longest-fibonacci-subsequence.go",
2424
"bookmarks": [
2525
{
26-
"line": 29,
26+
"line": 36,
2727
"column": 1,
2828
"label": ""
2929
}

Algorithms/0873.length-of-longest-fibonacci-subsequence/length-of-longest-fibonacci-subsequence.go

+7-4
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,19 @@ func lenLongestFibSubseq(a []int) int {
66
size := len(a)
77
res := 0
88

9-
for k := 2; k < size; k++ {
9+
// (size - k) + 2 > res 表示,此时的 k 至少还有可能让 res 变的更大
10+
// (size - k) + 2 > res ==> k < size - res + 2
11+
12+
for k := 2; k < size && k < size-res+2; k++ {
1013
l, r := 0, k-1
14+
1115
for l < r {
1216
s := a[l] + a[r]
1317

1418
if s < a[k] {
1519
l++
1620
continue
17-
}
18-
19-
if a[k] < s {
21+
} else if a[k] < s {
2022
r--
2123
continue
2224
}
@@ -38,6 +40,7 @@ func lenLongestFibSubseq(a []int) int {
3840
l++
3941
r--
4042
}
43+
4144
}
4245

4346
return res

0 commit comments

Comments
 (0)