Getting permutations of an int[] removing duplicates sets

后端 未结 5 1113
有刺的猬
有刺的猬 2020-12-11 23:06

I have an [] of integers 1<=N<=100 , How can i get permutations of this array? -> Array may contain duplicates, so resulting set of permutations can be duplicate, so

5条回答
  •  佛祖请我去吃肉
    2020-12-11 23:40

    You could use a Set instead of an array of ints, it could delete your duplications automatic.

    Edit: @allingeek give me an idea. More than implements your own Set you could write a wrapper over an int and overwrite your equals and hashcode methods, finding the way where your permutations are equals. Perhaps using the numbers in order and others advise given in "Effective Java" (for equals and hashcode implementations to avoid mistakes). It could give you a better way to find your permutations in the Set. More than use expressions language as I say at first.

提交回复
热议问题