this is my code

public class Solution {

public int removeElement(int[] nums, int val) {

int count=0;

int length=0;

```
for(int i=0;i<nums.length;i++){
if(val==nums[i]){
count++;
}
}
length=nums.length-count;
return length;
}
```

}

as the question, it ask for returning the new array's length.

i use a count to record the duplicate amount. then i use original array length minute count to give new length .

but why it gives me the wrong answer

Input:

[4,5], 4

Output:

[4]

Expected:

[5]