mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-04-18 03:37:35 +00:00
Merge branch 'longArthSub' of https://github.com/tejaswi0910/Python into longArthSub
This commit is contained in:
commit
cf444d645f
@ -9,6 +9,7 @@ Note that:
|
|||||||
seq.length - 1).
|
seq.length - 1).
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
def longest_arithmetic_subsequence(nums: list[int]) -> int:
|
def longest_arithmetic_subsequence(nums: list[int]) -> int:
|
||||||
"""
|
"""
|
||||||
Finds the length of the longest arithmetic subsequence in a given array of integers.
|
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:
|
if nums is None:
|
||||||
raise ValueError("Input array cannot be None")
|
raise ValueError("Input array cannot be None")
|
||||||
|
|
||||||
if len(nums) == 0:
|
if len(nums) == 0:
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
@ -61,6 +62,7 @@ def longest_arithmetic_subsequence(nums: list[int]) -> int:
|
|||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
import doctest
|
import doctest
|
||||||
|
|
||||||
doctest.testmod()
|
doctest.testmod()
|
||||||
# Sample test case
|
# Sample test case
|
||||||
nums = [3, 6, 9, 12]
|
nums = [3, 6, 9, 12]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user