实现一个汉诺塔游戏:每一步只允许移动一个圆盘,移动时,大圆盘不能在小圆盘上
参考代码:
class Solution: def move(self, n, a, b, c, ans): if n == 1: ans.append("from" + a + "to" + c) else: self.move(n-1, a, c, b, ans) ans.append("from" + a+"to"+c) self.move(n-1, b, a, c, ans) return ans