diff --git a/dynamic_programming/longest_arithmetic_subsequence.py b/dynamic_programming/longest_arithmetic_subsequence.py index 74cb11b0b..781af9ef6 100644 --- a/dynamic_programming/longest_arithmetic_subsequence.py +++ b/dynamic_programming/longest_arithmetic_subsequence.py @@ -9,6 +9,7 @@ Note that: seq.length - 1). """ + def longest_arithmetic_subsequence(nums: list[int]) -> int: """ Finds the length of the longest arithmetic subsequence in a given array of integers. @@ -40,7 +41,7 @@ def longest_arithmetic_subsequence(nums: list[int]) -> int: """ if nums is None: raise ValueError("Input array cannot be None") - + if len(nums) == 0: return 0 @@ -61,6 +62,7 @@ def longest_arithmetic_subsequence(nums: list[int]) -> int: if __name__ == "__main__": import doctest + doctest.testmod() # Sample test case nums = [3, 6, 9, 12]