leetcode873+最长的fibonaci,暴力

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u013554860/article/details/89045356

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        

猜你喜欢

转载自blog.csdn.net/u013554860/article/details/89045356