Skip to content

Practice Find the XOR of Numbers Which Appear Twice

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Easy#3158
LeetCode Problem

Find the XOR of Numbers Which Appear Twice

Problem Statement

You are given an array nums, where each number in the array appears either once or twice. Return the bitwise XOR of all the numbers that appear twice in the array, or 0 if no number appears twice.

Source: Find the XOR of Numbers Which Appear Twice on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
nums = [1,2,1,3]
Output
1

# Example 2

Input
nums = [1,2,3]
Output
0

# Example 3

Input
nums = [1,2,2,1]
Output
3

Constraints

1 <= nums.length <= 50
1 <= nums[i] <= 50
Each number in nums appears either once or twice.

Related LeetCode Problems

Practice more problems similar to Find the XOR of Numbers Which Appear Twice.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.