最长算术子序列
给定一个非空的有限整数序列,返回最大长度的算术子序列。 如果有多个相同的最大长度,则可以返回它们中的任何一个。 定义: 一个算术序列是这样的序列a(1),a(2),a(3),a(4),...,例如,有一个恒定的c,使得a(m+1)-a(m) = c对于所有m。换句话说:两个后续项之间的差是恒定的。 给定一个序列,b(1),b(2),b(3),b(4),...一个子序列就是一个序列b(s(1)),b(s(2)),b(s(3)),b(s(4)),...,其中1 <= s(1),s(m) < s(m+1)对于所有m。换句话说:采用原始顺序并删除所需的任意多个条目。 例子 Input Output [4,1,2,3,6,5] [1,3,5] or [1,2,3] [5,4,2,-1,-2,-4,-4] [5,2,-1,-4] [1,2,1,3,1,4,1,5,1] [1,1,1,1,1] or [1,2,3,4,5] [1] [1] 一些较长的测试用例: Length: 25 Input: [-9,0,5,15,-1,4,17,-3,20,13,15,9,0,-6,11,17,17,9,26,11,5,11,3,16,25] Output: [15,13,11,9] or [17,13,9,5] Length: 50 Input: [35,7,37,6,6,33,17,33,38,30,38,12,37,49,44,5,19,19,35,30,40,19,11,5,39,11,20,28,12,33,25,8,40,6,15,12,27,5,21,6,6,40,15,31,49,22,35,38,22,33] Output: [6,6,6,6,6] or [39,33,27,21,15] Length: 100 Input: [6,69,5,8,53,10,82,82,73,15,66,52,98,65,81,46,44,83,9,14,18,40,84,81,7,40,53,42,66,63,30,44,2,99,17,11,38,20,49,34,96,93,6,74,27,43,55,95,42,99,31,71,67,54,70,67,18,13,100,18,4,57,89,67,20,37,47,99,16,86,65,38,20,43,49,13,59,23,39,59,26,30,62,27,83,99,74,35,59,11,91,88,82,27,60,3,43,32,17,18] Output: [6,18,30,42,54] or …