Bottom Up Dynamic Programming Approach
Complexity\nLet $N$ be the length of nums and $M$ be the target\n \n- Time complexity:\n$O(N * M)$\n\n- Space complexity: $O(N * M)$ (Can be optimized to $O(M)$
# Complexity\nLet $N$ be the length of `nums` and $M$ be the target\n \n- Time complexity:\n$O(N * M)$\n\n- Space complexity: $O(N * M)$ (Can be optimized to $O(M)$)\n\n# Code\n```python3 []\nclass Solution:\n    def lengthOfLongestSubsequence(self, nums: List[int], target: int) -> int:\n        dp = [[0 for _ in range(target + 1)] for _ in range(len(nums) + 1)]\n        \n        for i in range(len(dp)):\n            dp[i][0] = 1\n\n        for i in range(1, len(dp)):\n            for j in range(1, len(dp[i])):\n                dp[i][j] = dp[i - 1][j]\n                if j - nums[i - 1] >= 0 and dp[i - 1][j - nums[i - 1]] > 0:\n                    dp[i][j] = max(dp[i - 1][j], 1 + dp[i - 1][j - nums[i - 1]])\n            \n        return dp[-1][-1] - 1\n\n```
['Python3']