Skip to content

Commit 84bf612

Browse files
authored
Merge pull request #6 from jonirrings/patch-1
Update n0026_remove_duplicates_from_sorted_array.rs
2 parents 0ba09bd + c55485c commit 84bf612

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/n0026_remove_duplicates_from_sorted_array.rs

+12-2
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,18 @@ pub struct Solution {}
4949

5050
impl Solution {
5151
pub fn remove_duplicates(nums: &mut Vec<i32>) -> i32 {
52-
nums.dedup();
53-
nums.len() as i32
52+
let len = nums.len();
53+
if len <= 1 {
54+
return len as i32;
55+
}
56+
let mut slow = 0usize;
57+
for fast in 1..len {
58+
if nums[slow] != nums[fast] {
59+
slow += 1;
60+
nums[slow] = nums[fast];
61+
}
62+
}
63+
(slow + 1) as i32
5464
}
5565
}
5666

0 commit comments

Comments
 (0)