[Python3] O(n * target) time and O(target) space DP
Traversal should be done from back to front to avoid overwriting results and causing errors.\n\nclass Solution:\n    def lengthOfLongestSubsequence(self, nums: 
Traversal should be done from back to front to avoid overwriting results and causing errors.\n```\nclass Solution:\n    def lengthOfLongestSubsequence(self, nums: List[int], target: int) -> int:\n        dp = [-1] * (target + 1)\n        for v in nums:\n            if v > target: continue\n            for i in range(target - v, -1, -1):\n                if dp[i] != -1: dp[i + v] = max(dp[i + v], dp[i] + 1)\n            dp[v] = max(dp[v], 1)\n        return dp[target]\n```
['Python3']