登录
  • #刷题
  • #careercup

【第三轮】6.30-7.6 CareerCup 3.4

wrj5518
2495
23
3.4 In the classic problem of the Towers of Hanoi, you have 3 towers and Ndisks of different sizes which can slide onto any tower.The puzzle starts with disks sorted in ascending order of size from top to bottom (i.e., each disk sits on top of an even larger one). You have the following constraints:

(1) Only one disk can be moved at a time.

(2) A disk is slid off the top of one tower onto the next tower.

(3) A disk can only be placed on top of a larger disk.

Write a program to move the disks from the first tower to the last using stacks.

回复解法可以按照以下格式来

[indent]
【解题思路】

【时间复杂度】

【空间复杂度】

【gist link】

---------------Optional,如果觉得test case比较好,欢迎写出来分享----------------------

【test case】


[/indent]


Notice:

1、记得在程序注释中表明自己算法的时间、空间复杂度

2、代码难懂之处加注释

3、每道题目有对应的帖子,除了贴解法,欢迎讨论,集思广益

4、任何未尽之处,欢迎回报名帖提问,我会进一步作出修改。
23条回复
热度排序

发表回复