aboutsummaryrefslogtreecommitdiff
path: root/other/remove_dupplicate.rs
diff options
context:
space:
mode:
Diffstat (limited to 'other/remove_dupplicate.rs')
-rw-r--r--other/remove_dupplicate.rs24
1 files changed, 24 insertions, 0 deletions
diff --git a/other/remove_dupplicate.rs b/other/remove_dupplicate.rs
new file mode 100644
index 0000000..c192b22
--- /dev/null
+++ b/other/remove_dupplicate.rs
@@ -0,0 +1,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));
+}