Shuffle an array as many as possible

前端 未结 8 1365
一向
一向 2020-12-07 05:21

I have an array like this

[0,2,3]

The possible shuffling of this array are

[0,2,3], [2,3,0], [3,0,2], [3,2,0], [0,3,2],         


        
8条回答
  •  借酒劲吻你
    2020-12-07 06:00

    Try a recursive approach. Here's a hint: every permutation of [0,2,3] is either

    • [0] plus a permutation of [2,3] or
    • [2] plus a permutation of [0,3] or
    • [3] plus a permutation of [0,2]

提交回复
热议问题