If you dont get C today, u will miss the boat!!!# Stock
p*e
1 楼
我是用swap 来做permutation这个题的,但是如果input是有dup的,那么output也可能
会有dup。大家帮我看看问题出在哪儿?
vector> permutationHelper(vector& data, int start){
vector> rt;
if (start == data.size()-1) {
rt.push_back(data);
return rt;
}
for (int i=start; i if (i != start && data[i] == data[start]) continue;
if (i > start && data[i] == data[i-1]) continue;
vector set = data;
swap(set, start, i);
vector> perm = permutationHelper(set, start+1);
rt.insert(rt.end(), perm.begin(), perm.end());
}
return rt;
}
会有dup。大家帮我看看问题出在哪儿?
vector
vector
if (start == data.size()-1) {
rt.push_back(data);
return rt;
}
for (int i=start; i
if (i > start && data[i] == data[i-1]) continue;
vector
swap(set, start, i);
vector
rt.insert(rt.end(), perm.begin(), perm.end());
}
return rt;
}