我一定是miss了什么重要的算法 又被一道题block了
Given an array A of integers, return the length of the longest arithmetic subsequence in A.
给出一个数组中最长的arithmetic子数组的长度。
解释arithmetic
that a sequence B is arithmetic if B[i+1] - B[i] are all the same value
(俺的解释:就是从数组中按顺序挑选出的subarray 不用连续,但是前后不能颠倒。 选出来的元素相邻两个的差都是相等的)
看例子最明白
Input: [3,6,9,12]
Output: 4
Explanation: The whole array is an arithmetic sequence with steps of length = 3.
Input: [9,4,7,2,10]
Output: 3
Explanation: The longest arithmetic subsequence is [4,7,10].
Input: [20,1,15,3,10,5,8]
Output: 4
Explanation: The longest arithmetic subsequence is [20,15,10,5].
Given an array A of integers, return the length of the longest arithmetic subsequence in A.
给出一个数组中最长的arithmetic子数组的长度。
解释arithmetic
that a sequence B is arithmetic if B[i+1] - B[i] are all the same value
(俺的解释:就是从数组中按顺序挑选出的subarray 不用连续,但是前后不能颠倒。 选出来的元素相邻两个的差都是相等的)
看例子最明白
Input: [3,6,9,12]
Output: 4
Explanation: The whole array is an arithmetic sequence with steps of length = 3.
Input: [9,4,7,2,10]
Output: 3
Explanation: The longest arithmetic subsequence is [4,7,10].
Input: [20,1,15,3,10,5,8]
Output: 4
Explanation: The longest arithmetic subsequence is [20,15,10,5].