Not able to understand string permutation Java code

后端 未结 3 462
清歌不尽
清歌不尽 2021-01-07 06:32

I have this working code to print string permutations without repetitions, but not able to wrap my head around how is it working as in logic. Any suggestions will be really

3条回答
  •  天涯浪人
    2021-01-07 07:14

     for (int i = 0; i < input.length(); i++) {
    

    The above for loop is doing the magic

    Input ABCD

    Iterations

    input: BCD sofar: A .... recursion goes on

    input: ACD sofar: B ....

    input: ABD sofar: C ....

    input: ABC sofar: D .....

    Hope this helps

提交回复
热议问题