From 44d659123601a09f5973e48d999f3e74c5609970 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 3 Oct 2024 17:43:22 +0000 Subject: [PATCH] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- dynamic_programming/longest_arithmetic_subsequence.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/dynamic_programming/longest_arithmetic_subsequence.py b/dynamic_programming/longest_arithmetic_subsequence.py index f82aa886d..31d6572ab 100644 --- a/dynamic_programming/longest_arithmetic_subsequence.py +++ b/dynamic_programming/longest_arithmetic_subsequence.py @@ -1,4 +1,5 @@ from typing import List + """ Longest Arithmetic Subsequence Problem: Given an array nums of integers, return the length of the longest arithmetic subsequence in nums. @@ -8,6 +9,7 @@ Note that: - A sequence seq is arithmetic if seq[i + 1] - seq[i] are all the same value (for 0 <= i < 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. @@ -39,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) <= 1: return len(nums) @@ -57,6 +59,7 @@ def longest_arithmetic_subsequence(nums: List[int]) -> int: if __name__ == "__main__": import doctest + doctest.testmod() # sample test case nums = [3, 6, 9, 12]