Find the errors and correct then in the given code with proper comments. class Solution { public: vector DistinctSum(vectornums){ vectorans; int sum = 0; int n = nums.size() for(int i=0;i
Find the errors and correct then in the given code with proper comments.
class Solution {
public:
vector<int>ans;
int sum = 0;
int n = nums.size()
for(int i=0;i<n;i+){
}
bool dp[n+1][sum+1];
for(int i=0;i<=n;i+){
dp[i][0] = true
}
for(int i=1;i<=n;i++){
for(int j = 1;j<sum;j++){
if(dp[i-1][j]=true){
dp[i][j+nums[i-1]] = true;
}
}
}
for(int j=0;j<=sum;j++){
if(dp[n][j]==false){
ans.push_back(j);
}
}
return a;
}
};
Ques: Given a set of integers, find all distinct sums that can be generated from the subsets of the given sets.
Find the errors in the given code and correct them with proper comments.
Problem Statement:
Given a set of integers, find all distinct sums that can be generated from the subsets of the given sets.
Step by step
Solved in 3 steps with 2 images