Lonely Integer

  • + 0 comments

    My solution in Rust, it takes advantage of the XOR properties. they key is that every has only one duplicate eccept one (correct me if I'm wrong) and XOR is commutative and associative:

    fn lonelyinteger(a: &[i32]) -> i32 {
        a.iter().fold(0, |acc, x| *x ^ acc)
    }