You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/** * @param {number} n - 圆盘数量 * @param {string} A - 源柱子名称 * @param {string} B - 辅助柱子名称 * @param {string} C - 目标柱子名称 */functionhanoi(n,A,B,C){// 你的代码}
测试用例:
hanoi(3,'A','B','C');// 控制台输出:/* Move disc 1 from A to C Move disc 2 from A to B Move disc 1 from C to B Move disc 3 from A to C Move disc 1 from B to A Move disc 2 from B to C Move disc 1 from A to C*/
参考答案:
functionhanoi(n,A,B,C){if(n>0){hanoi(n-1,A,C,B);console.log(`Move disc ${n} from ${A} to ${C}`);hanoi(n-1,B,A,C);}}
Activity