剑指offer_27_去重全排列

class Solution {

public:
void rPermutation(int k, string cststr, vector &rtvec) {
if (k == cststr.size() - 1)
rtvec.push_back(cststr);
for (int i = k; i < cststr.size(); i++)
{
if (i != k && cststr[k] == cststr[i])
continue;
swap(cststr[i], cststr[k]);
rPermutation(k + 1, cststr, rtvec);
}
}
vector Permutation(string str) {
vector rtvec;
sort(str.begin(), str.end());
rPermutation(0, str, rtvec);
return rtvec;
}

};


int main()
{
Solution mys;
vector rtvec=mys.Permutation("1231");
}

你可能感兴趣的:(C\C++,数据结构与算法分析)