summaryrefslogtreecommitdiff
path: root/sort-array-by-parity/src/main.rs
blob: 6deb88d9adacf3a665e4e8300bb0f8ea6dd4cd5b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
fn main() {
    println!("Hello, world!");

    let tests = [
        vec![3,1,2,4],
        vec![0]
    ];

    for test in tests {
        println!("{:?} {:?}", test, Solution::sort_array_by_parity(test.clone()));
    }
}

struct Solution;

impl Solution {
    pub fn sort_array_by_parity(nums: Vec<i32>) -> Vec<i32> {
        let mut result = nums.clone();
        result.sort_by_key(|x| x % 2);
        result
    }
}