filmov
tv
Leetcode 2425. Bitwise XOR of All Pairings - use basic XOR properties

Показать описание
See other videos @codeyao9796
Python solution to Leetcode 2425 - Bitwise XOR of All Pairings. Here we use the two basic properties of XOR: 1. commutative and associative; 2. a ^ a = 0. Key observation: if len(nums2) is even, then each number in nums1 contribute to the final res by 0; if len(nums2) is odd, then each number in nums1 contribute to the final res by the number itself. It is similar for looking at the contributions of numbers from nums2. So this problem is reduced to compute the XOR result of numbers in nums1 and/or nums2.
Python solution to Leetcode 2425 - Bitwise XOR of All Pairings. Here we use the two basic properties of XOR: 1. commutative and associative; 2. a ^ a = 0. Key observation: if len(nums2) is even, then each number in nums1 contribute to the final res by 0; if len(nums2) is odd, then each number in nums1 contribute to the final res by the number itself. It is similar for looking at the contributions of numbers from nums2. So this problem is reduced to compute the XOR result of numbers in nums1 and/or nums2.