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