Given a sorted array, remove the duplicates in place such that each element appear only once
and return the new length.
Do not allocate extra space for another array, you must do this in place with constant memory.
For example, Given input array A = [1,1,2],
Your function should return length = 2, and A is now [1,2].
题目含义:给一个有顺序的数组,去掉重复的元素
fn main(){
let mut v = vec![1,2,3,3,4,4];
let a_len = remove_duplicate(&mut v);
for i in 0..a_len{
println!("{}",v[i]);
}
}
fn remove_duplicate(v: &mut Vec<usize>) -> uszie {
let mut index=0;
for i in 0..v.len(){
if v[index] != v[i] {
index = index +1;
v[index]=v[i];
}
}
index +1
}