class Solution {
public:
vector<string> Fun(string input){
vector<string> tmp;
// tmp.insert(tmp.end(), input.begin(), input.end());
tmp.push_back(input);
if(idx >= input.length()-1)
return tmp;
int k = 0;
while(k < 1){
idx ++;
vector<string> tmp_out = Fun(input);
//tmp.insert(tmp.end(), tmp_out.begin(), tmp_out.end());
tmp = tmp_out;
idx --;
string str = input;
for(int i = idx; i < idx +1; i++){
for(int j = i +1; j < str.length(); j++){
if(str[i] != str[j]){
char center;
center = str[i];
str[i] = str[j];
str[j] = center;
//tmp.push_back(str);
idx++;
vector<string> in_tmp = Fun(str);
tmp.insert(tmp.end(), in_tmp.begin(), in_tmp.end());
idx --;
str[j] = str[i];
str[i] = center;
}
}
}
k ++;
}
//idx ++
//vector<string> output = Fun(tmp);
//tmp.insert(tmp.end(), output.begin(), output.end());
return tmp;
}
vector<string> Permutation(string str) {
if(str.length() == 0)
return vector<string>();
vector<string> output = Fun(str);
sort(output.begin(), output.end(), [](string a, string b) -> bool{
//cout << a << " " << b << endl;
for(int i = 0; i < a.length(); i++){
//cout << int(a[i]) << " " << int(b[i]) << endl;
if((int(a[i]) - int(b[i])) > 0)
return false;
else if((int(a[i]) - int(b[i])) < 0){
return true;
}
}
return true;
});
//tmp.insert(tmp.end(), output.begin(), output.end());
return output;
}
private:
int idx = 0;
};