Repeat arrangement in Java (string form: 0000111222)

I have a string in the form of 00001122222 That is, consecutive numbers repeat randomly without Time Other examples may be:

0011122223333
01222    
00011234444
001122222

wait. I know, for a string 01222, a total of 5/ 3! Permutation is possible I need to generate all these permutations for each such string

I have tried to generate permutations in various ways One is to generate all possible permutations (like no duplicate strings), but since the string I will use may be very large, it may waste time and produce too many redundant permutations

Secondly, I try to put a number at the random index of the character array to equal the size of the string, and terminate the loop when the number count is the same as the input string However, I wasted a lot of memory and time

I need an efficient way to generate permutations for these strings Just an algorithm or code, welcome I'm using Java

thank you!

Solution

One of the standard algorithms used to generate permutations is @ L_ 301_ 0@. The algorithm is composed of C STD:: next_ Most implementations of permutation algorithm use permutation to generate permutations at most o (n) time per permutation and skip repeated permutations of all permutations the other one. Coding is also very easy

I hope this can help!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>