题目描述:
class Solution: def longestSubsequence(self, arr: List[int], difference: int) -> int: dp = dict() for a in arr: pre = a - difference if pre in dp: dp[a] = max(dp.get(a, 0), dp[pre] + 1) else: dp[a] = 1 return max([x for _, x in dp.items()])