From a78fac5f215df77c645f15a26ace20931980b6c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5kon=20St=C3=B8rdal?= <30749741+hakon55@users.noreply.github.com> Date: Sat, 22 Mar 2025 13:54:43 +0100 Subject: [PATCH] rename --- .../Cargo.toml | 0 .../src/main.rs | 0 .../Cargo.toml | 0 .../src/main.rs | 25 +++++++++++++++++++ .../Cargo.toml | 0 .../src/main.rs | 0 6 files changed, 25 insertions(+) rename {merge-two-sorted-lists => merge-two-sorted-lists-21}/Cargo.toml (100%) rename {merge-two-sorted-lists => merge-two-sorted-lists-21}/src/main.rs (100%) rename {remove_duplicates => remove-duplicates-from-sorted-array-26}/Cargo.toml (100%) create mode 100644 remove-duplicates-from-sorted-array-26/src/main.rs rename {roman-to-integer => roman-to-integer-13}/Cargo.toml (100%) rename {roman-to-integer => roman-to-integer-13}/src/main.rs (100%) diff --git a/merge-two-sorted-lists/Cargo.toml b/merge-two-sorted-lists-21/Cargo.toml similarity index 100% rename from merge-two-sorted-lists/Cargo.toml rename to merge-two-sorted-lists-21/Cargo.toml diff --git a/merge-two-sorted-lists/src/main.rs b/merge-two-sorted-lists-21/src/main.rs similarity index 100% rename from merge-two-sorted-lists/src/main.rs rename to merge-two-sorted-lists-21/src/main.rs diff --git a/remove_duplicates/Cargo.toml b/remove-duplicates-from-sorted-array-26/Cargo.toml similarity index 100% rename from remove_duplicates/Cargo.toml rename to remove-duplicates-from-sorted-array-26/Cargo.toml diff --git a/remove-duplicates-from-sorted-array-26/src/main.rs b/remove-duplicates-from-sorted-array-26/src/main.rs new file mode 100644 index 0000000..806f13e --- /dev/null +++ b/remove-duplicates-from-sorted-array-26/src/main.rs @@ -0,0 +1,25 @@ +pub fn remove_duplicates(nums: &mut Vec) -> i32 { + if nums.is_empty() { + return 0; + } + + let mut i = 0; + for j in 1..nums.len() { + if nums[j] != nums[i] { + i += 1; + nums[i] = nums[j]; + } + } + + nums.truncate(i + 1); // Remove extra elements + (i + 1) as i32 +} + +fn main() { + let mut nums = vec![1, 1, 2]; + let new_length = remove_duplicates(&mut nums); + + println!("New length: {}", new_length); + println!("Modified nums: {:?}", &nums[..new_length as usize]); // Print only the unique part + println!("Hello, world!"); +} diff --git a/roman-to-integer/Cargo.toml b/roman-to-integer-13/Cargo.toml similarity index 100% rename from roman-to-integer/Cargo.toml rename to roman-to-integer-13/Cargo.toml diff --git a/roman-to-integer/src/main.rs b/roman-to-integer-13/src/main.rs similarity index 100% rename from roman-to-integer/src/main.rs rename to roman-to-integer-13/src/main.rs