面试题 08.06. 汉诺塔问题

  • 递归
class Solution {
public void hanota(List<Integer> A, List<Integer> B, List<Integer> C) {
move(A.size(), A, B, C);
}
public void move(int size, List<Integer> a, List<Integer> b, List<Integer> c) {
if (size == 1) {
c.add(a.remove(a.size() - 1));
return;
}
move(size - 1, a, c, b);
c.add(a.remove(a.size() - 1));
move(size - 1 , b, a, c);
}
}