Skip to content
Go back

2425-bitwise-xor-of-all-pairings

2425 https://leetcode.cn/problems/bitwise-xor-of-all-pairings/

XOR运算

struct Solution {}

impl Solution {
  pub fn xor_all_nums(nums1: Vec<i32>, nums2: Vec<i32>) -> i32 {
    let x1 = nums1.iter().fold(0, |acc, x| acc ^ x);
    let x2 = nums2.iter().fold(0, |acc, x| acc ^ x);

    match (nums1.len() % 2, nums2.len() % 2) {
      (0,0) => 0,
      (0,1) => x1,
      (1,0) => x2,
      (_,_) => x1^x2
    }
  }
}

Share this post on:

Previous Post
474-ones-and-zeroes
Next Post
2512-reward-top-k-students