JAVA solution, Missing some number when N=6, why?


  • 0
    C

    I dont like back-tracking java solution. It not the best solution for me.

    My solution is store all lists for N-1, and adding number N into table, switch every possible num from old list to generate new list.

    For example, when N=5, there's one beautiful arrangement [4 2 3 1 5], when N = 6:
    first we add 6, we get [4 2 3 1 5 6]
    then we switch 2 with 6 => [4 6 3 1 5 2]
    then switch 3 with 6 => [4 2 6 1 5 3]

    adding these 3 solution back into queue, and continue with other N=5 beautiful arrangements.

    But for some reason, for N=1-5, answer is correct. Starting N=6, my solution is 32, but answer is 36;

    Can some one please correct my logic?


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.