We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 85c132c commit e4a41e8Copy full SHA for e4a41e8
1 file changed
028-字符串的排列/README.md
@@ -200,20 +200,26 @@ public:
200
i++)
201
{
202
//debug <<str[i] <<str[begin] <<endl;
203
- if(i == begin || str[i] != str[begin])
+ if(!HasDuplicate(str, begin, i))
204
205
-
206
swap(str[i], str[begin]);
207
+ debug <<"swap " <<str[i] <<"(" <<i <<")" <<" and " <<str[begin] <<"(" <<begin <<")" <<endl;
208
PermutationRecursion(str, begin + 1);
209
+ //copy(str.begin( ), str.degin( ) + i, ostream_iterator<char>(cout," "));
210
211
212
}
213
214
215
216
+
+private:
+ //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
+ }
223
};
224
225
int __tmain( )
0 commit comments