I am working on an algorithm problem on Leetcode. But first I wrote my answer on my own local compiler. When running my code locally, I can get the answer to this question. But when I paste my answer directly into the online compiler on leetcode, the system prompts me that my answer is wrong. Cannot match the correct answer.
The solution from my local compiler shown below:
class Solution {
public int removeDuplicates(int[] nums) {
ArrayList<Integer> list = new ArrayList<Integer>();
ArrayList<Integer> arraylist = new ArrayList<Integer>();
for (int i : nums) {
list.add(i);
}
for (int num : list) {
if (!arraylist.contains(num)) {
arraylist.add(num);
}
}
return arraylist.size();
}
}
And the feedback from LeetCode:
enter image description here
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…