LeetCode/rs/minimum-number-of-operations-to-make-array-xor-equal-to-k.rs

6 lines
164 B
Rust
Raw Permalink Normal View History

impl Solution {
pub fn min_operations(nums: Vec<i32>, k: i32) -> i32 {
(k ^ nums.into_iter().reduce(|x, y| x ^ y).unwrap()).count_ones() as i32
}
}