summaryrefslogtreecommitdiff
path: root/find-all-lonely-numbers-in-the-array/src/main.rs
blob: 1f1e6f9839d74d974cf16fcde12bff5c8d944ab9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
fn main() {
    println!("Hello, world!");
}

struct Solution;

impl Solution {
    pub fn find_lonely(mut nums: Vec<i32>) -> Vec<i32> {
        if nums.len() == 1 {return nums;}

        nums.sort();

        let mut result: Vec<i32> = nums.windows(3).filter(|arr| (arr[0] - arr[1]).abs() > 1).flat_map(|arr| Vec::from(arr)).collect();
        result.dedup();
        result
    }
}