A sequence X_1, X_2, ..., X_n is fibonacci-like if:

  • n >= 3
  • X_i + X_{i+1} = X_{i+2} for all i + 2 <= n

Given a strictly increasing array A of positive integers forming a sequence, find the length of the longest fibonacci-like subsequence of A.  If one does not exist, return 0.

(Recall that a subsequence is derived from another sequence A by deleting any number of elements (including none) from A, without changing the order of the remaining elements.  For example, [3, 5, 8] is a subsequence of [3, 4, 5, 6, 7, 8].)

Example 1:

Input: [1,2,3,4,5,6,7,8]
Output: 5
Explanation: The longest subsequence that is fibonacci-like: [1,2,3,5,8].

Example 2:

Input: [1,3,7,11,12,14,18]
Output: 3
Explanation:
The longest subsequence that is fibonacci-like:
[1,11,12], [3,11,14] or [7,11,18].

Note:

  • 3 <= A.length <= 1000
  • 1 <= A[0] < A[1] < ... < A[A.length - 1] <= 10^9
  • (The time limit has been reduced by 50% for submissions in Java, C, and C++.)

参考资料:

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

LeetCode All in One 题目讲解汇总(持续更新中...)

[LeetCode] Length of Longest Fibonacci Subsequence 最长的斐波那契序列长度的更多相关文章

  1. [LeetCode] Split Array into Fibonacci Sequence 分割数组成斐波那契序列

    Given a string S of digits, such as S = "123456579", we can split it into a Fibonacci-like ...

  2. 最长斐波那契序列-LeetCode-873

    英文版A sequence X_1, X_2, ..., X_n is fibonacci-like if: - n >= 3- X_i + X_{i+1} = X_{i+2} for all ...

  3. 【LeetCode】873. Length of Longest Fibonacci Subsequence 解题报告(Python)

    [LeetCode]873. Length of Longest Fibonacci Subsequence 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: ...

  4. [Swift]LeetCode873. 最长的斐波那契子序列的长度 | Length of Longest Fibonacci Subsequence

    A sequence X_1, X_2, ..., X_n is fibonacci-like if: n >= 3 X_i + X_{i+1} = X_{i+2} for all i + 2 ...

  5. LC 873. Length of Longest Fibonacci Subsequence

    A sequence X_1, X_2, ..., X_n is fibonacci-like if: n >= 3 X_i + X_{i+1} = X_{i+2} for all i + 2 ...

  6. LeetCode 873. 最长的斐波那契子序列的长度 题目详解

    题目详情 如果序列 X_1, X_2, ..., X_n 满足下列条件,就说它是 斐波那契式 的: n >= 3 对于所有 i + 2 <= n,都有 X_i + X_{i+1} = X_ ...

  7. [Swift]LeetCode842. 将数组拆分成斐波那契序列 | Split Array into Fibonacci Sequence

    Given a string S of digits, such as S = "123456579", we can split it into a Fibonacci-like ...

  8. LeetCode 873. Length of Longest Fibonacci Subsequence

    原题链接在这里:https://leetcode.com/problems/length-of-longest-fibonacci-subsequence/ 题目: A sequence X_1, X ...

  9. [LeetCode] Number of Longest Increasing Subsequence 最长递增序列的个数

    Given an unsorted array of integers, find the number of longest increasing subsequence. Example 1: I ...

随机推荐

  1. kalilinux渗透测试笔记

    声明:本文理论大部分是苑房弘kalilinux渗透测试的内容 第五章:基本工具 克隆网页,把gitbook的书记下载到本地 httrack "http://www.mybatis.org/m ...

  2. spring cloud 学习笔记(1)

    SpringCloud + Eureka / Nacos git:https://github.com/huanmsf/springCloudLearn.git 项目目录: 父pom: <?xm ...

  3. W3CSchool闯关笔记(JQuery)

    <script> $(document).ready(function(){ }); </script> <!-- Only change code above this ...

  4. SpringBoot整合Swagger测试api构建

    @Author:SimpleWu 什么是Swagger? Swagger是什么:THE WORLD'S MOST POPULAR API TOOLING 根据官网的介绍: Swagger Inspec ...

  5. BeanUtils.copyProperties缓解代码压力,释放双手

    简单描述:之前在写代码的时候,经常把表单提交到后台的对象的参数,通过getter方法取出来,然后,再通过setter方法传递给需要的对象,代码中写了很多get set这种方法,后来听同事说,sprin ...

  6. 记录MYSQL中SQL语句的一个坑.

    MYSQL5.7 假设我们有一个表 : h_member_cards_my  (ID, WXOPEN_ID) 表中有一条记录如下: 理论上第二个SQL应当是可以查询得到一条数据的, 结果却为 Empt ...

  7. emacs Can't guess python-indent-offset, using defaults: 4

    首先,这只是一个提示,Emacs 在打开python 文件时,如果是个空文件,会有此提示. 在python.el文件配置中,有如下代码: Python.el (defcustom python-ind ...

  8. 【Windows】JDK安装与环境变量配置

    一.JDK下载 jdk有多个版本: java se开发包:Java SE Development Kit 8u25 ,必须的配置Java开发环境的.java se开发包+示例:Java SE Deve ...

  9. CF1065F Up and Down the Tree

    题解: 和正解方法不太一样 正解的大概意思就是先向下走可以走回来的 再走不能走回来的 能走回来的就是到这个儿子后最近的叶子可以返回的 然后这样可以O(n)计算 我自己做的时候以为这样不太能做.. 所以 ...

  10. Scrapy 扩展中间件: 针对特定响应状态码,使用代理重新请求

    0.参考 https://doc.scrapy.org/en/latest/topics/downloader-middleware.html#module-scrapy.downloadermidd ...