Skip to content

Commit fee3054

Browse files
committed
daily
1 parent dff078c commit fee3054

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

my-submissions/m2425.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
Logic:
2+
3+
Take arrays A and B. If B is of even length, then each element of A will
4+
be XORed into the total of an even number of times, negating itself. This
5+
applies to all values in the array. Thus we can skip it if B is even length.
6+
7+
The same applies vise versa.
8+
9+
Besides that, an odd number of times no matter how many will be just like
10+
if there was only 1 XOR for that value since all others would negate it.
11+
This is clear when you look at the definition of an odd integer: $x=2y+1$
12+
where $x$ is your odd value and $y$ is an integer.

my-submissions/m2425.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class Solution:
2+
def xorAllNums(self, nums1: List[int], nums2: List[int]) -> int:
3+
return (reduce(xor, map(int, nums1)) if len(nums2) % 2 else 0) ^ (reduce(xor, map(int, nums2)) if len(nums1) % 2 else 0)

0 commit comments

Comments
 (0)