I'm not sure how this is incorrect, it's not identical to the solution in terms of syntax but it should have the same functionality:

```
int length = 1;
int prev = nums[0];
for (int i=1; i < nums.length; i++){
if (nums[i] != prev){
prev = nums[i];
length++;
}
}
return length;
}
```