递归脑壳疼
class Solution {
public:
void hanoi(std::vector<std::string> &description, int n,
std::string left, std::string mid, std::string right) {
if (n == 1) {
description.emplace_back("move from " + left + " to " + right);
return ;
}
hanoi(description, n-1, left, right, mid);
description.emplace_back("move from " + left + " to " + right);
hanoi(description, n-1, mid, left, right);
}
vector<string> getSolution(int n) {
std::vector<std::string> description;
hanoi(description, n, "left", "mid", "right");
return description;
}
};