leetcode
leetcode copied to clipboard
Bug Report for remove-element
Bug Report for https://neetcode.io/problems/remove-element
Please describe the bug below and include any steps to reproduce the bug or screenshots if possible.
Here again, my simplest solution in Java for this problem is as follows:
class Solution {
public int removeElement(int[] nums, int val) {
List<Integer> newNums = new ArrayList<>();
for(int num: nums){
if(num != val){
newNums.add(num);
}
}
return newNums.size();
}
}
The response on the platform is:
Input: nums=[1,1,2,3,4] val=1
Your Output: [1,1,2]
Expected output: [2,3,4]
My output is not correct according to the platform; I tested it out in an IDE, and the content of my variable (newNums) at the end is [2,3,4].