Tabulation Cpp
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\nTabulation approach \n\n# Complexity\n- Time complexity:\nO(nm)\n\n- Spac
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\nTabulation approach \n\n# Complexity\n- Time complexity:\nO(n*m)\n\n- Space complexity:\nO(n*m)\n\n# Code\n```cpp []\nclass Solution {\npublic:\n  \n    int lengthOfLongestSubsequence(vector<int>& nums, int target) {\n        int n=nums.size();\n        vector<vector<int>> dp(n+1,vector<int>(target+1,-1));\n        dp[0][0]=0;\n        for(int i=1;i<=n;i++){\n            for(int j=0;j<=target;j++){\n                dp[i][j]=dp[i-1][j];\n                if(j>=nums[i-1]&&dp[i-1][j-nums[i-1]]!=-1){\n                    dp[i][j]=max(dp[i][j],1+dp[i-1][j-nums[i-1]]);\n                }\n            }\n        }\n        return dp[n][target];\n    }\n};\n```
['C++']