码迷,mamicode.com
首页 > 其他好文 > 详细

剑指offer--字符串的排列

时间:2017-08-06 12:26:39      阅读:112      评论:0      收藏:0      [点我收藏+]

标签:star   ring   字符串的排列   ==   turn   art   cto   ++   public   

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;
    }
};

 

剑指offer--字符串的排列

标签:star   ring   字符串的排列   ==   turn   art   cto   ++   public   

原文地址:http://www.cnblogs.com/159269lzm/p/7294166.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!