20240404 Finished
This commit is contained in:
parent
174a17f94c
commit
86b7a4ff84
|
@ -92,3 +92,4 @@ mod p2908_minimum_sum_of_mountain_triplets_i;
|
||||||
mod p2952_minimum_number_of_coins_to_be_added;
|
mod p2952_minimum_number_of_coins_to_be_added;
|
||||||
mod p331_verify_preorder_serialization_of_a_binary_tree;
|
mod p331_verify_preorder_serialization_of_a_binary_tree;
|
||||||
mod p88_merge_sorted_array;
|
mod p88_merge_sorted_array;
|
||||||
|
mod p26_remove_duplicates_from_sorted_array;
|
33
src/problem/p26_remove_duplicates_from_sorted_array.rs
Normal file
33
src/problem/p26_remove_duplicates_from_sorted_array.rs
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
/**
|
||||||
|
* [26] Remove Duplicates from Sorted Array
|
||||||
|
*/
|
||||||
|
pub struct Solution {}
|
||||||
|
|
||||||
|
|
||||||
|
// submission codes start here
|
||||||
|
|
||||||
|
impl Solution {
|
||||||
|
pub fn remove_duplicates(nums: &mut Vec<i32>) -> i32 {
|
||||||
|
let mut now = 1;
|
||||||
|
|
||||||
|
for i in 1..nums.len() {
|
||||||
|
if nums[i] != nums[i - 1] {
|
||||||
|
nums[now] = nums[i];
|
||||||
|
now += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
now as i32
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// submission codes end
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_26() {
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user