编辑代码

function hanota(A, B, C) {
    // 只剩最后一个盘子就直接移动
    movePlate(A.length, A, B, C)

    //size 需要移动的盘子的数量
    //start 起始的柱子
    //auxiliary 辅助柱子
    //target 目标柱子

    // 函数的作用: 将起始的柱子移动到目标柱子
    function movePlate(size, start, auxiliary, target) {
        // 只剩下一个盘子后直接移动到目标柱子
        if (size === 1) {
            target.push(start.pop())
            return
        }
        // 首先将上面的移动到辅助柱子
        // 先将size-1个盘子移动到第二个柱子
        movePlate(size - 1, start, target, auxiliary) // 子问题e
        //然后将最后一个盘子移动到第三个柱子上
        target.push(start.pop())
        //最后将第二个柱子上的 n-1 个盘子,移动到第三个柱子上
        movePlate(size - 1, auxiliary, start, target)

    }
};
const A = [2, 1, 0]
const B = []
const C = []
hanota(A, B, C)
console.log(A, B, C)