Loading RustViz Engine...
Remove duplicate elements from a sorted mutable slice in O(1) extra memory.
This problem is currently in blueprint template mode. Once the concept foundation is finalized, live in-browser WebAssembly compilation and test assertion runners will be enabled here.
pub fn remove_duplicates(nums: &mut Vec<i32>) -> usize {
if nums.is_empty() { return 0; }
let mut write = 1;
for read in 1..nums.len() {
if nums[read] != nums[write - 1] {
nums[write] = nums[read];
write += 1;
}
}
nums.truncate(write);
write
}