[JAVA]  ✅ Accepted | Coin Change Pattern | Recursion + Memoization | Easy Code
\n\n# Complexity\n- Time complexity:O(n^2)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity: O(n^2)\n Add your space complexity here, e.g. O(n)
\n\n# Complexity\n- Time complexity:$$O(n^2)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(n^2)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n    private int solve(List<Integer> nums, int i, int target, Integer[][] dp) {\n        if(target == 0) {\n            return 1;\n        }\n        if(target < 0 || i < 0) {\n            return 0;\n        }\n        \n        if(dp[i][target] != null) {\n            return dp[i][target];\n        }\n        \n        int include = solve(nums, i-1, target-nums.get(i), dp);\n        int dontInclude = solve(nums, i-1, target, dp);\n        \n        int res = 0;\n        if(include == 0 && dontInclude == 0) {\n            res = 0;\n        } else {\n            res = Math.max(include+1, dontInclude);\n        }\n        return dp[i][target] = res;\n    }\n    public int lengthOfLongestSubsequence(List<Integer> nums, int target) {\n        return solve(nums, nums.size()-1, target, new Integer[nums.size()][target+1])-1;\n    }\n}\n```
['Dynamic Programming', 'Memoization', 'Java']