Algorithm to generate all combinations of a string

前端 未结 10 1937
日久生厌
日久生厌 2021-02-01 22:47

I found a link online that shows an algorithm to generate all combinations of a string: http://www.mytechinterviews.com/combinations-of-a-string

Algorithm is copied belo

10条回答
  •  醉话见心
    2021-02-01 23:15

    outstr.deleteCharAt(outstr.length() - 1); 
    

    means that you have

    n^(n-1)/2 pairs of combinations.
    

    The iterative for-loop doesn't stop after the recursive function call so you need to delete the last char in the output buffer because you don't want to get

    n^n/2 pairs of combinations.
    

    In a graph theory it would be a short circuit.

提交回复
热议问题