File tree 1 file changed +4
-1
lines changed
1 file changed +4
-1
lines changed Original file line number Diff line number Diff line change 1
1
from typing import List
2
+
2
3
"""
3
4
Longest Arithmetic Subsequence Problem: Given an array nums of integers, return the length of the longest arithmetic subsequence in nums.
4
5
8
9
- A sequence seq is arithmetic if seq[i + 1] - seq[i] are all the same value (for 0 <= i < seq.length - 1).
9
10
"""
10
11
12
+
11
13
def longest_arithmetic_subsequence (nums : List [int ]) -> int :
12
14
"""
13
15
Finds the length of the longest arithmetic subsequence in a given array of integers.
@@ -39,7 +41,7 @@ def longest_arithmetic_subsequence(nums: List[int]) -> int:
39
41
"""
40
42
if nums is None :
41
43
raise ValueError ("Input array cannot be None" )
42
-
44
+
43
45
if len (nums ) <= 1 :
44
46
return len (nums )
45
47
@@ -57,6 +59,7 @@ def longest_arithmetic_subsequence(nums: List[int]) -> int:
57
59
58
60
if __name__ == "__main__" :
59
61
import doctest
62
+
60
63
doctest .testmod ()
61
64
# sample test case
62
65
nums = [3 , 6 , 9 , 12 ]
You can’t perform that action at this time.
0 commit comments