Typical DP Question | Recursion with Memoization | Rust
Complexity\n- Time complexity: O(mn)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity: O(mn)\n Add your space complexity here, e.g. O(n) \n\n# 
# Complexity\n- Time complexity: $$O(m*n)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(m*n)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nimpl Solution {\n    pub fn length_of_longest_subsequence(nums: Vec<i32>, target: i32) -> i32 {\n        let mut memo = vec![vec![-1; target as usize]; nums.len()];\n        let ans = dp(0, 0, &nums, &mut memo);\n        if ans <= 0 { -1 } else { ans }\n    }\n}\n\nfn dp(i: usize, j: usize, nums: &Vec<i32>, memo: &mut Vec<Vec<i32>>) -> i32 {\n    if j == memo[0].len() { return 0 };\n    if i >= nums.len() ||\n       j > memo[0].len() { return i32::MIN };\n    if memo[i][j] != -1 { return memo[i][j] };\n    \n    memo[i][j] = dp(i + 1, j, nums, memo).max(\n        dp(i + 1, j + nums[i] as usize, nums, memo) + 1\n    );\n    memo[i][j]\n}\n```
['Rust']