blob: c192b223001b503649bfb2b965de845ed62ea51f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
struct Solution;
impl Solution {
pub fn remove_duplicates(nums: &mut Vec<i32>) -> i32 {
match nums.is_empty() {
true => 0,
false => {
let mut prev = 0;
for i in 1..nums.len() {
if nums[prev] != nums[i] {
prev += 1;
nums[prev] = nums[i];
}
}
(prev + 1) as i32
}
}
}
}
fn main() {
let mut nums = vec![0,0,1,1,1,2,2,3,3,4];
print!("{}", Solution::remove_duplicates(nums));
}
|