![]() ![]() Forming a string just to dump the entry to a stream involves unnecessary allocation and copying. Use an array of characters and write the characters to the stream one-by-one when it's time to emit a particular permutation. It's the rare case that you actually have to write the letters out to the destination stream, so bias your solution against that operation. String is a poor choice, given that it's immutable, when generating permutations is best done by swapping and rotating elements in a vector (really, a ring). Note too that most of the solutions posted here use type String and keep chopping it up and reassembling it. ![]() Try writing it out on paper, recording the steps you take to shuffle the elements, and you'll find you've written the program you need. You can iterate down the sequence, swapping the chosen element with the last element, reversing the sequence, expanding the bottom 24 permutations each time.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |