leetcode873+最长的fibonaci,暴力

https://leetcode.com/problems/length-of-longest-fibonacci-subsequence/

class Solution(object):
    def lenLongestFibSubseq(self, A):
        """
        :type A: List[int]
        :rtype: int
        """
        s = set(A)
        cnt = 0
        for i in range(len(A)):
            for j in range(i+1, len(A)):
                a,b = A[i],A[j]
                t = 2
                while a+b in s:
                    a, b = b, a+b
                    t = t+1
                if t>=3:
                    cnt = max(cnt, t)
        return cnt        

 

你可能感兴趣的:(Leetcode)