剑指offer--字符串的排列

class Solution 
{
public:
    void quanpailie(vector<string> &shuchu, string &temp, int start, int end)
    {
        if (start == end)
        {
            shuchu.push_back(temp);
        }

        for (int i = start; i <= end; ++i)
        {
            if (temp[start] == temp[i]&&i!=start)
            {
                continue;
            }
            else
            {
                swap(temp[start], temp[i]);
                quanpailie(shuchu, temp, start + 1, end);
                swap(temp[start], temp[i]);
            }
        }
    
    }

    vector<string> Permutation(string str)
    {
        int start = 0;
        int end = (str.size() - 1);
        vector<string> re;
        quanpailie(re, str, 0,end);
        sort(re.begin(), re.end());
        return re;
    }
};

 

posted @ 2017-08-06 11:04  双马尾是老公的方向盘  阅读(131)  评论(0编辑  收藏  举报