summaryrefslogtreecommitdiff
path: root/remove-element/src/main.rs
blob: 807cd97febb5adb3b9de9a230a559a0803f48677 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
fn main() {
    println!("Hello, world!");
}

struct Solution;

impl Solution {
    pub fn remove_element(nums: &mut Vec<i32>, val: i32) -> i32 {
        let elements: Vec<_> = nums.iter().enumerate().filter(|(_,&num)| num == val).map(|(i,_)| i).collect();
        for i in &elements {
            nums.remove(*i);
        }
        elements.len() as i32
    }
}