-
Notifications
You must be signed in to change notification settings - Fork 187
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #907 from 0xff-dev/873
Add solution and test-cases for problem 873
- Loading branch information
Showing
3 changed files
with
47 additions
and
23 deletions.
There are no files selected for viewing
30 changes: 16 additions & 14 deletions
30
leetcode/801-900/0873.Length-of-Longest-Fibonacci-Subsequence/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 25 additions & 2 deletions
27
leetcode/801-900/0873.Length-of-Longest-Fibonacci-Subsequence/Solution.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,28 @@ | ||
package Solution | ||
|
||
func Solution(x bool) bool { | ||
return x | ||
func Solution(arr []int) int { | ||
nums := make(map[int]struct{}) | ||
for _, n := range arr { | ||
nums[n] = struct{}{} | ||
} | ||
var try func(int, int, *int) | ||
try = func(a, b int, c *int) { | ||
_, ok := nums[a+b] | ||
if !ok { | ||
return | ||
} | ||
*c++ | ||
try(b, a+b, c) | ||
} | ||
ans := 0 | ||
for i := 0; i < len(arr)-1; i++ { | ||
for j := i + 1; j < len(arr); j++ { | ||
c := 0 | ||
try(arr[i], arr[j], &c) | ||
if c != 0 { | ||
ans = max(ans, c+2) | ||
} | ||
} | ||
} | ||
return ans | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters