class Solution: def lenLongestFibSubseq(self, A: List[int]) -> int: s = set(A) n = len(A) result = 0 for i in range(n-1): for j in range(i+1, n): a, b = A[i], A[j] count = 2 while a+b in s: a, b = b, a+b count += 1 # A= [1,2,3,4,5,6,7,8] # [1,2,3,5,8] # [1,3,4,7] # [1,4,5] # ... # 取其中最大的序列长度 result = max(result, count) return result if result > 2 else 0
873. 最长的斐波那契子序列的长度
猜你喜欢
转载自www.cnblogs.com/WJZheng/p/11393426.html
今日推荐
周排行