最初は、時間計算量が 0(n^2) の Nested ループを使用しました。より効率的な 0(n) の解決策として、以下のコードを書きました。いずれかの要素とその .Next() が同じ値を保持しているかどうかを確認する方法について、ヘルプ/洞察を得たいと思います。それらを出します。
public class FindDuplicates {
public static void main(String arg[]){
int[] str={1 , 2 , 3 ,4 ,5 ,3 ,5 , 4,3,43,1,33,4,5};
List<Integer> list = new LinkedList<Integer>();
for(int x : str) {
list.add(x);
}
Collections.sort(list);
System.out.println(list);
Iterator<Integer> it = list.listIterator();
while(it.hasNext() && it.next() != null) {
/* Pseudocode => if(it.next().equals(it.next.next)); */
/* OR Pseudocode => if(it.next() == it.next().next) */
System.out.println(it) ;
}
}
}