class Solution { public: void f(int i, vector<int> &a, int n,int sum, vector<int> &v,vector<int> &vv) { if(i == n) { vv.push_back(sum); return; } f(i+1,a,n,sum+a[i],v,vv); f(i+1,a,n,sum,v,vv); } vector<int> subsetSums(vector<int> arr, int n) { vector<int> v; vector<int> vv; f(0,arr,n,0,v,vv); sort(vv.begin(),vv.end()); return vv; } };
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter