-3
我在遍歷LinkedList,但無法弄清楚如何遍歷每個唯一的字符串。我正在考慮使用ForEach循環遍歷每個唯一的字符串,但不確定它是否可能或如何去做。謝謝!如何停止鏈接列表中的重複字符串?
@Override
public List<String> listRegressions() {
// TODO Implement this, ideally in better than O(n^2)
LinkedList<String> regressionUnikey = new LinkedList<String>();
for (int i = 0; i < getListSize(); i++) {
Integer bestGrade = getBestGrade(students.get(i).getUnikey());
Integer recentGrade = getSubmissionFinal(students.get(i).getUnikey()).getGrade();
if (recentGrade < bestGrade) {
regressionUnikey.add(students.get(i).getUnikey());
}
}
return regressionUnikey;
}
一個測試用例結果
java.lang.AssertionError: expected:<[b, c, f]> but was:<[b, b, c, c, f, f]>
爲什麼不使用Set?你真的需要一個列表嗎? – Carcigenicate
將列表轉換爲Set並遍歷Set。 – agurylev
使用LinkedList的具體原因是什麼? – Ravi