Sales by Match

  • + 0 comments

    My rust solution:

    fn sockMerchant(n: i32, ar: &[i32]) -> i32 {
        let odd_socks = ar.iter().fold(HashSet::new(), |mut acc, sock| {
            if acc.remove(sock) == false {
                acc.insert(sock);
            }
            acc
        })
        .len() as i32;
        
        (n - odd_socks) / 2
    }