DP | Python3
Intuition\nSame as length of shortest subsequence\n\n# Code\n\nclass Solution:\n    def lengthOfLongestSubsequence(self, nums: List[int], target: int) -> int:\n
# Intuition\nSame as length of shortest subsequence\n\n# Code\n```\nclass Solution:\n    def lengthOfLongestSubsequence(self, nums: List[int], target: int) -> int:\n        n = len(nums)\n        dp = [[float("-inf")]*(target+1) for i in range(n+1)]\n\n        for i in range(n+1):\n            for j in range(target+1):\n                if j == 0:\n                    dp[i][j] = 0\n                elif i !=0:\n                    if j >= nums[i-1]:\n                        dp[i][j] = max(dp[i-1][j], dp[i-1][j-nums[i-1]] + 1)\n                    else:\n                        dp[i][j] = dp[i-1][j]\n\n\n        return dp[n][target] if dp[n][target] != float("-inf") else -1\n\n\n        \n```
['Dynamic Programming', 'Python3']