Smart way to generate permutation and combination of String

前端 未结 7 462
耶瑟儿~
耶瑟儿~ 2021-02-01 22:37
String database[] = {\'a\', \'b\', \'c\'};

I would like to generate the following strings sequence, based on given database.



        
7条回答
  •  暖寄归人
    2021-02-01 23:13

    This smells like counting in binary:

    • 001
    • 010
    • 011
    • 100
    • 101
    • ...

    My first instinct would be to use a binary counter as a "bitmap" of characters to generate those the possible values. However, there are several wonderful answer to related questions here that suggest using recursion. See

    • How do I make this combinations/permutations method recursive?
    • Find out all combinations and permutations - Java
    • java string permutations and combinations lookup
    • http://www.programmerinterview.com/index.php/recursion/permutations-of-a-string/

提交回复
热议问题