File tree Expand file tree Collapse file tree 1 file changed +12
-6
lines changed Expand file tree Collapse file tree 1 file changed +12
-6
lines changed Original file line number Diff line number Diff line change @@ -200,20 +200,26 @@ public:
200
200
i++)
201
201
{
202
202
//debug <<str[i] <<str[begin] <<endl;
203
- if(i == begin || str[i] != str[begin] )
203
+ if(!HasDuplicate(str, begin, i) )
204
204
{
205
-
206
205
swap(str[i], str[begin]);
207
-
206
+ debug <<"swap " <<str[i] <<"(" <<i <<")" <<" and " <<str[begin] <<"(" <<begin <<")" <<endl;
208
207
PermutationRecursion(str, begin + 1);
209
-
208
+ //copy(str.begin( ), str.degin( ) + i, ostream_iterator<char>(cout," "));
210
209
swap(str[i], str[begin]);
211
-
212
210
}
213
211
}
214
212
}
215
213
}
216
-
214
+
215
+ private:
216
+ //find duplicate of str[i] in str[k,i)
217
+ bool HasDuplicate(string& str, int k, int i) const {
218
+ for (int p = k; p < i; p++)
219
+ if (str[p] == str[i]) return true;
220
+
221
+ return false;
222
+ }
217
223
};
218
224
219
225
int __tmain( )
You can’t perform that action at this time.
0 commit comments