#include <string>
class Solution {
public:
//汉诺塔递归函数
void han(vector<string>& a,int n,string A,string B,string C)
{
if(n==1)
{
string t="move from "+A+" to "+C;
a.push_back(t);
return;
}
han(a,n-1,A,C,B);
string t="move from "+A+" to "+C;
a.push_back(t);
han(a,n-1,B,A,C);
}
vector<string> getSolution(int n) {
vector<string> a;
han(a,n,"left","mid","right");
return a;
}
};

京公网安备 11010502036488号