Say I have a List<List<Integer>>
that contains Lists of numbers from 1 to n. What is a good way of removing lists with the same members but in different indexes?
Like if I have [[1,2,3], [2,1,3], [4,5,6]]
, I am considering the first and the second member as duplicates and I want to remove one of them (doesn't matter which one) to get [[2,1,3], [4,5,6]]
or [[1,2,3], [4,5,6]]
.
There is one O(n^2)
solution by looping through all the members and using list.contains(x)
or even using a List<Set<Integer>>
but I wonder if there is a better solution to do this.