牛客OJ:字符串的枚举排列

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/ShellDawn/article/details/88942811
class Solution {
public:
    vector<string> Permutation(string str) {
        if(str.length() < 1) return *(new vector<string>);
        char s[10];
        memset(s,0,sizeof(s));
        int l = str.length();
        for(int i=0;i<l;i++){
            s[i] = str[i];
        }
        sort(s,s+l);
        string t;
        vector<string> ans;
        do{
            for(int i=0;i<l;i++) t += s[i];
            ans.push_back(t);
            t = "";
        }while(next_permutation(s,s+l));
        return ans;
    }
};

猜你喜欢

转载自blog.csdn.net/ShellDawn/article/details/88942811