Back to course home
0% completed
Vote For New Content
DP / recursive solution
Mohammed Dh Abbas
Oct 14, 2024
class Solution: def countSubsets(self, num, s): def dp(index, acc, memo): if (index, acc) in memo: return memo[(index, acc)] if acc == s: return 1 if index == len(num): return 0 result = dp(index + 1, acc, memo) + dp(index + 1, acc + num[index], memo) memo[(index, acc)] = result return result return dp(0, 0, {})
0
0
Comments
Comments
On this page
Problem Statement
Try it yourself