beat 62%
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<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```python3 []\nclass Solution:\n    def lengthOfLongestSubsequence(self, nums: List[int], target: int) -> int:\n        n = len(nums)\n        f = [-inf] * (target + 1)\n        f[0] = 0\n\n        nums = sorted(nums)\n\n        for x in nums:\n            for c in range(target, x - 1, -1):\n                if c >= x:\n                    f[c] = max(f[c], f[c - x] + 1)\n            # print(f)\n\n        ans = f[target]\n        return ans if ans > -inf else -1\n\n```
['Python3']