Forked from anonymous/Generate all binary strings of length n with k bits set.cpp
Last active
August 29, 2015 14:14
-
-
Save duyet/55c91420c9fafbf54691 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
vector<string> answer; | |
void getStrings( string s, int digitsLeft ) | |
{ | |
if( digitsLeft == 0 ) // the length of string is n | |
answer.push_back( s ); | |
else | |
{ | |
getStrings( s + "0", digitsLeft - 1 ); | |
getStrings( s + "1", digitsLeft - 1 ); | |
} | |
} | |
getStrings( "", n ); // initial call |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment