Time - O(t*n). Space - O(t).
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n$$O(t*n)$$\n\n- Space complexity:\n$$O(t)$$\n\n# Code\n```\nclass Solution {\n    func lengthOfLongestSubsequence(_ nums: [Int], _ target: Int) -> Int {\n        var dp = [1] + Array(repeating: 0, count: target)\n        nums.forEach { num in\n            for i in stride(from: target, through: num, by: -1) where dp[i - num] > 0 {\n                dp[i] = max(dp[i], dp[i - num] + 1)\n            }\n        }\n        return dp[target] > 0 ? dp[target] - 1 : -1\n    }\n}\n```
['Swift']