Skip to content

Commit

Permalink
Create 9.Power Set.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
mridul8920 authored Oct 15, 2021
1 parent 6ca22fb commit f62afc1
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions Bit Manipulation/9.Power Set.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
void filterchars(int n,string s,vector<string> &v){
int j=0;
string temp="";
while(n>0){
int last_bit=(n&1);
if(last_bit){
temp+=s[j];
}
j++;
n=n>>1;
}
if(temp.length())
v.push_back(temp);
}
vector<string> AllPossibleStrings(string s){
// Code here
int n=s.size();
vector<string> v;
for(int i=0;i<(1<<n);i++){
filterchars(i,s,v);
}
sort(v.begin(),v.end());
return v;
}

0 comments on commit f62afc1

Please sign in to comment.