Given an array nums of integers, return the length of the longest arithmetic subsequence in nums.
Note that:
seq is arithmetic if seq[i + 1] - seq[i] are all the same value (for 0 <= i < seq.length - 1).
Example 1:
Input: nums = [3, 6, 9, 12]
Output: 4
Explanation: The whole array is already an arithmetic sequence with a common difference of 3, so the longest arithmetic subsequence is [3, 6, 9, 12], of length 4.
Example 2:
Input: nums = [9, 4, 7, 2, 10]
Output: 3
Explanation: The longest arithmetic subsequence is [4, 7, 10] (indices 1, 2, 4), with a common difference of 3. There is no arithmetic subsequence of length 4.
Example 3:
Input: nums = [20, 1, 15, 3, 10, 5, 8]
Output: 4
Explanation: The longest arithmetic subsequence is [20, 15, 10, 5] (indices 0, 2, 4, 5), with a common difference of -5.
Constraints:
2 <= nums.length <= 15000 <= nums[i] <= 500